Flex 2 / Apollo Memory Leak? Try re-using objects.
Having problems with excessive memory usage in Flex 2 or Apollo? As long as an object in memory is still referenced, it won’t be deleted. Since there are so many references floating around, especially given binding and effects, it’s easy to think you’ve purged all references to an object when you actually haven’t. Thus, that something won’t get cleaned up.
I was recently working on a project for which the view rotated through a constant amount of data: as new data entered the screen, an equal amount of old data exited. Every time new data came into view and old data went out, I created a new DisplayObject to use as the new data’s visual representation. As for the exiting old data… well, I tried to remove all references to it. I watched, frustrated, as the memory usage climbed each time new data came into the view.
Then I tried this: re-using objects. Since I new there would only ever be 10 or less objects on screen, I created ten of those objects, reusing old instances whenever I needed to visually represent some new data. That did the trick — my memory usage dropped dramatically.
This may require a little finagling with your code, but it’s worth it when you watch your total memory usage drop. Give it a go, and let me know if it helps.
Loading...
Extremely long blog name? Try giving it a few other clever names so we can’t keep it updated on our blog-rolls.
Just kidding. Nice work dude. Keep it up! You’ve inspired me to actually write posts.
Andy McIntosh - June 15, 2007 at 5:41 am
Good stuff. This reminds me of the flash tip of re-using assets from your library instead of creating new items on the stage.
eric fickes - July 22, 2008 at 6:54 pm