Flash Image Sequence Memory Issues
April 9th, 2009 • ActionScript, Flash
I guess most of you are aware of the Bitmap memory leak in Flash Player and that you have to call the BitmapData.dispose() method to actually free the memory. But what to do if you don’t have a reference to the BitmapData?
That’s essentially a problem when dealing with MovieClips with an image sequence on its timeline. After adding the MovieClip to the stage and accessing each frame the complete sequence is in memory and removing it from the stage again doesn’t free any of this memory. Obviously the single frames are getting converted to Shapes with bitmap fill internally, so you don’t have a Bitmap instance for each frame and therefore you can’t dispose the frames after showing the sequence.
Sequence Example (the swf has no preloader, so you’ll probably have to wait a little bit)
Sequence Example Source (9MB, Flash CS3)
The only solution for this problem is to load the sequence as an external swf and call the unload method of your Loader instance when you don’t need the sequence anymore and want to free the memory. Alternatively you could load the single jpg frames individually, create your sequence programmatically and use BitmapData.dispose() afterwards.
3 Responses (Add Your Comment)
-
-
Janusz July 21, 2009at 10:51 am
Hi Martin,
Greetings from Poland.
I just found your post, because I’m having a similar problem. It turns out that when you place an image inside a movie clip and you export your bitmap (image properties->Export for Action Script) the instance in the movie clip is no longer a Shape but a Bitmap instance.
Hey Martin, nice one, though (assuming you’re talking AS3 here) calling the unload() method won’t do much for you memory-wise as there is a garbagecollection-issue in FP9 preventing the memory taken up by loaded content to be released in most cases. Check it out:
http://www.gskinner.com/blog/archives/2008/04/failure_to_unlo.html