codewow – how hard is it to stop memory leaks in AS3? Programming for FP10 AIR in Flex, I have a class that loads an image from the web by setting the source property on the image to a url.

I add and remove many instances of the class on the display list. I get lots of memory leakage. All my listeners are weakly referenced, I even remove the event listeners when I unload the class instances. I also delete everything I’ve created. Still memory leaks. It turns out, and it took a while to find this, that you need to “unloadAndStop(true)” on images you’ve loaded, then they get unloaded from memory. Now, no memory leaks.

There don’t seem to be many mentions of this, certainly one to watch out for if you’re having memory problems!

2 Responses to “Fix image memory leaks in Air / AS3”
  1. Cristi says:


    I have also the same problem when loading images with URLLoader or UILoader. After 10 min memory runs out. unloadAndStop(true) doesn`t help.
    Any sugestion?


  2. Rúben says:

    Cristi, be sure to unloadAndStop(true) on your URLLoader or UILoader object, like this:


    Also, be sure to only do that after the image is loaded or if some problem occurs, like onIOErrorEvent or something.

Leave a Reply

6 − five =