Flash Image Sequence Memory Issues

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)

  1. 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

  2. hi ruben, thanks for your comment. I know about the gc issue but if you don’t have any timeline code running in the loaded swf and clean up all references to the loaded content you are able to free the memory using Grants “Force GC” hack. (http://www.gskinner.com/blog/archives/2006/08/as3_resource_ma_2.html) I just used this method in a current project and it works.

  3. 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.

Leave a Reply

Formatting: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

Other Entries

About

Martin Rädlinger is an Interactive Developer & Designer. He specializes in interactive coding predominantly with ActionScript, but every new challenge is welcome. If you like his work feel free to get in touch with him. At the moment he's available for freelance work.

Contact

Martin Rädlinger
mail: mr [at] formatlos.de
web: www.formatlos.de
xing: Martin Rädlinger
linkedin: Martin Rädlinger
skype: martinraedlinger