unload you module

24 July, 2009
by Oleg

If you are using modules in your application sooner or later you will get some nice memory leaks, 100% guarantee. It’s “simples”, not much effort required, just add TextInput to your module. The FocusManager keeps references to all focusable components in private focusableCandidates property (SDK 3.4.0). When you are trying to unload your module, the FocusManager doesn’t revalidate the list of focusable candidates leaving references to one or more components owned by the module. Unless you explicitly set focus to any other TextInput outside the module before actually invoking unload procedure, the module will never get garbage collected introducing some nice source of memory leaks.

The issue has already been reported to Adobe Jira by my colleague from the previous project. The bug exists in Flex SDK 3.4.0 and 4.0.0 as well.

I assume you vote to prioritize this issue as it is very serious bug stopping any developer from utilizing modular infrastructure in flex applications.

9 Responses leave one →
  1. 26 July, 2009
    Kenny Yates permalink

    Oleg,

    Thanks for this article.
    Although my client’s app architecture rarely requires modules, currently one of them does.

    We will make adjustments using FocusManager to set focus to a field
    on the “main” screen before unloading the currently loaded module.

    Kenny Yates
    http://truitgroup.com/flexgenie

  2. 7 August, 2009
    Alex Harui permalink

    When the module is removed from the display list, the FocusManager will remove those objects from the focusableCandidates. There could still be some bug in there, but it has cleaned up focusableCandidates successfully in all leak investigations so far.

    It is true that the last focused item will be referenced by the FocusManager, but a good application will set focus somewhere else and that will free that reference.

    But I will say that we have seen that the Flash Player also caches the last focused object and even if you move focus somewhere else, it takes several other tabs and mouse clicks before it releases that object. But so far we’ve seen that it does release it.

    I’m working on a summary of module unloading issues that will be posted on my blog soon.

    • 17 August, 2009
      Oleg permalink

      Alex, thank you for the comment. It will be great to have some guidance how to work with modules in Flex 3 and Flex 4.
      Modules in flex is great way to create enterprise level application. But there are still too many problems to make it really usable especially in terms of rapid application development. From my colleagues’ and my experience I can tell you that making sure that module is unloaded from memory and fully garbage collected is a very time consuming and frustrating experience. There are multiple issues that stop modules from being garbage collected still exist in both versions of SDK. While working on huge financial flex application we’ve found out that using inline styles, inline effects, focusable components, charting components and popups in modules leads to memory problems in most of the cases. Sometimes it’s happening due to running effects, sometimes due to not unregistered event listeners etc.
      It would be really useful and very appreciated if you guys will implement native support module load/unload workflow not in Flex SDK but in Flash Player.

      Regards,
      Oleg

  3. 17 August, 2009
    handoyo permalink

    Hi Oleg,i want to ask.How to check if there are memory leak?Is it by looking at the performance in windows task manager?Thanks..

    • 17 August, 2009
      Oleg permalink

      Hi Handoyo,
      you may easily identify memory leaks if you profile your application if Flex/Flash Builder using memory snapshots. Once you launch your application you may take memory snapshot( before loading module), then load your module, do some module’s workflow, and unload module. After unloading of the module you can take another memory snapshot and compare with previously taken snapshot. If you can see some instances that supposed to be destroyed – you definitely have some memory problems as some instances not garbage collected, that potentially can lead to serious memory issues. Using task manager is good way to identify possible memory leaks as well but mostly to answer the general question if you have it or not. I’d recommend you to use first approach.

  4. 18 August, 2009
    handoyo permalink

    Thanks Oleg,by the way,are there any approach to handle the memory leak at the moment?Thanks…

Trackbacks & Pingbacks

  1. MAX Presentation – Tackling Memory & Performance in Flash, Flex, and AIR | The World In A State of Flex
  2. Thoughts On Sproutcore and App Dev In General « lukesh +interactive
  3. Thoughts On Sproutcore and App Dev In General | lukesh

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS