RL1 Modular Memory Leak

dada's Avatar


06 Jun, 2012 03:07 PM


We recently discovered a GC issue with the Joel Hooks modular extension, concerning the automatic instanciation of mediators.

Case :
1) Instanciate a module "A" and display a view "V"
2) Release the module A and instanciate a module "B"
3) Release the module B and reinstanciate the module A, and display the view V
4) Issue is that two mediators are instanciated for the view V for the last ADDED_TO_STAGE event

If, after the step 2, we force the garbage collection, there is no issue.

The reason is that, at step 3, the mediatorMap and viewMap of the step 1 are still in memory, listening for the ADDED_TO_STAGE, they are ready to be garbage collected but the GC only comes when it wants, and on small modules its doesn't come at every module change. So when the view V is added to stage, the event is received by the mediatorMap and viewMap of the two modules : the old A and the new A.

We did this fix :
1) Sub-class of MediatorMap with a public method dispose() that calls removeListeners().
2) Sub-class of ViewMap with a public method dispose() that calls removeListeners().
3) Sub-class of ModuleContext :
- The mediatorMap and viewMap getters returns our own maps. - The dispose method call dispose() method of maps. 4) When a module is released, we call its dispose() method.

Was it a known issue ?

  1. Support Staff 1 Posted by Joel Hooks on 06 Jun, 2012 04:54 PM

    Joel Hooks's Avatar

    Hey dada, I don't believe this is a known issue. Would you mind creating a pull request with your fix? I'd love to check it out and see about pulling it in.

    You think it is something that could be recreated in a unit test?

  2. 2 Posted by dada on 07 Jun, 2012 02:29 PM

    dada's Avatar

    Hi Joel,

    I did the pull request with the fixes in sub-classes.
    I added 3 unit tests, 2 are GC dependant so maybe they can fail in some conditions, but they "work on my machine" (TM). :-)

    Tell me if you want more informations.

  3. Ondina D.F. closed this discussion on 27 Aug, 2012 10:38 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