My friends and family are under attack in Ukraine.
Donate to protect them directly or help international organizations.

Garbage collection with SWF loading

September 25th, 2008

I ran some performance tests today. I made an interesting discovery. When you load a SWF that has elements exported for ActionScript, the class definitions of these elements are stored in the application's domain and take up memory (we already knew that). But whether you load these definitions into the SWF's context or your main application's context will determine whether that memory is ever released.

I tried loading SWFs using the Loader class and unloading them immediately after the load completes. These SWFs contained symbols that were exported for ActionScript (linkage). When providing a LoaderContext with its applicationDomain property set to ApplicationDomain.currentDomain, even if you unload the SWF, memory of that symbol definition is never released. However, if you do not provide one, when you unload the SWF, memory is released.

Conclusion: if you are to use linked library symbols in your projects, avoid loading it in the application's domain for performance reasons. In one of my projects, I used it intensely and my application lagged and crashed after a few hours of use (could be much less depending on the size of the symbols that you have).

Previous: Flex: working with MovieClips Next: Weak Event Listeners Warning