Unloading application

jakub.gondek's Avatar


17 Sep, 2013 09:02 AM


I'm workin on an AIR application for Android tablet. The app consists of AIR launcher and SWF that is loaded into it. The SWF has Robotlegs context and Starling/Feathers UI in it. In my tests loading and unloading SWF causes memory usage to rise until the app stops responding.

My question is - what is the proper way of tearing down the context, that the whole SWF get garbage collected?

  1. Support Staff 1 Posted by Ondina D.F. on 17 Sep, 2013 03:47 PM

    Ondina D.F.'s Avatar

    Hi Jakub,

    My question is - what is the proper way of tearing down the context, that the whole SWF get garbage collected?

    The only 'proper' way I know of is to get rid of any references to objects or classes that could keep that SWF in memory ;)

    If you're using Flash Builder, the Flash Profiler is a good tool to find out what's keeping the objects alive.
    I'm sure you already know a lot about gc and memory management, so please excuse me if the following tips aren't new to you..

    [1] Clean up the views when they get removed from stage:

    • remove event listeners
    • remove child components
    • remove external references
    • remove effects references, tweening listeners, functions references
    • remove bindings
    • be aware of styles, item renderers that might keep the view alive

    [2] Allow Mediators to be destroyed:

    If views are mediated, make sure to remove all registered events and signals listeners. If you're using addViewListener to add event listeners, they will be automatically removed when mediator's destroy() runs. But, if you add listeners directly to the view or its subcomponents, you have to manually remove them inside your destroy() method. If you're using Signals, destroy() is also the place were you should -manually- remove the listeners. If you forget to do so, the Signals will keep your view and/or mediator alive!!!

    Here something about stylesheets, in case you're using any:

    and the articles he mentioned:

    [3] Unloading Modules


    Can you get into details about how are you loading/unloading the SWF?

    [4] Make sure that Starling doesn't keep your Views from being gc-ed - are you using a robotlegs extension for Starling?

    GC and memory management is a huge subject. I've only scratched the surface with the above tips, which are focused only on Views and Mediators.
    It's hard to know what's going on in your project without seeing it or without knowing more about your concrete use case, so, if all of the above doesn't help, then you might want to attach your project, or a bare-bone example where you can reproduce the issues you've encountered, and I'll take a look at it.
    Also, you might want to test your swf without robotlegs, if possible, to see if it gets gc-ed when unloaded.

    Let me know how it goes.


  2. Ondina D.F. closed this discussion on 11 Oct, 2013 08:53 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac