I’m building an application which uses external swf movies loaded through the Loader class. I noticed a memory leak early on which was caused by event listeners which were not removed. Thanks to the advices in this forum, I converted all of my listeners to use weak references and removed them after use. That pretty much solved part of my problem.
However, I observed that I could not unload (from memory) external swf files with components put in at author time in the usual manner that is, calling Loader.unload(). To confirm this, I put the application through the debugger and put in the hack which forces the GC to run. Next, I observed the output window which displays the ff: (paths removed for simplicity)
Attemping to launch and connect to Player using URL Emulator.swf
[SWF] Emulator.swf - 3427 bytes after decompression
[SWF] Intro.swf - 967388 bytes after decompression
[SWF] Main Menu.swf - 414225 bytes after decompression
[UnloadSWF] Intro.swf
[SWF] Credits.swf - 208881 bytes after decompression
[UnloadSWF] Main Menu.swf
[SWF] Main Menu.swf - 414225 bytes after decompression
[UnloadSWF] Credits.swf
[SWF] Activities.swf - 306062 bytes after decompression
[UnloadSWF] Main Menu.swf
[SWF] Main Menu.swf - 414225 bytes after decompression
[SWF] Credits.swf - 208881 bytes after decompression
[SWF] Main Menu.swf - 414225 bytes after decompression
[UnloadSWF] Credits.swf
The main file Emulator.swf is the one calling the Loader.load() method as well as the Loader.unload() method. As you can see, “Main Menu.swf” and “Credits.swf” get unloaded successfully (with corresponding memory usage drops) but “Activities.swf” does not get unloaded (because it has a TextArea component). I tested this once more by modifying another movie removing the component instance on stage and the code associated with it. I could now unload this movie as a result.
Do component instances have some sort of reference with the parent timeline which cannot be removed or something? I thought that the parent timeline is supposed to be the one containing a reference to the component instance.
Any thoughts on this matter?