When loading bitmaps, your loader will NEVER be eligible for cleanup by the Garbage Collector unless you do ALL of the following in this order:

var bitmap:Bitmap = new Bitmap(Bitmap(loader.content).bitmapData.clone(), "auto", true);
Bitmap(loader.content).bitmapData.dispose();
loader.unloadAndStop(true);
try {
    loader.close();
} catch (e:Error) {}
// remove all event listeners from loader

This means that if you want the Bitmap from the loader, you should extract it using bitmapData.clone(), or your Bitmap will be gone when the loader goes away or the loader will not go away because there's still a reference to its BitmapData.

If you're pulling a Bitmap out of an anonymous loader by saying addChild(loader.content) you will never have another opportunity to get rid of the loader. That may be ok for your purposes, but this is a very good reason to addChild(loader) so you maintain a reference to the loader itself.

Unless you have a specific reason for not using addChild(loader) you should use the code block above.

It's important to note that you won't see your memory go down unless you force the GC to run after you null out all references to the loader. In AIR you can say System.gc(). In Flash, you have to use the unsupported LocalConnection hack.
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to