Mediators Garbage collection issue

PJ's Avatar


11 Jan, 2012 07:55 AM

I am facing a problem regarding garbage collection of Mediator .
I have two different states for a component which has Two sub components having mapped mediators. When i change the state from first to second and navigate back to first state , new instance of sub-component which is in first state is created along with its mediator, but what i observed is that there are two mediators working for same view.The number of mediators keeps on adding as i keep on toggling between two states.I have also kept weakreferences true for all listeners. Can Anyone help me in this.

  1. Support Staff 1 Posted by Ondina D.F. on 11 Jan, 2012 09:58 AM

    Ondina D.F.'s Avatar

    Hi PJ,

    mediatorMap.mapView(SomeView, SomeMediator, null, true, true);
    The last two parameters autoCreate and autoRemove are boolean switches that provide convenient automatic mediator management, by default set to true.
    If you set autoRemove to false, the Mediator won’t be removed after the View has been removed from the display list.
    Try this and tell if it solved your issue.


  2. 2 Posted by PJ on 11 Jan, 2012 10:48 AM

    PJ's Avatar

    Thanks for your suggestion , I tried it but still there is no success . I am still observing multiple mediators acting for single view events.

  3. Support Staff 3 Posted by Ondina D.F. on 11 Jan, 2012 10:54 AM

    Ondina D.F.'s Avatar

    Could you attach a stripped out example exhibiting the issue or paste some relevant code. I will take a look at it.

  4. Support Staff 4 Posted by Ondina D.F. on 11 Jan, 2012 01:37 PM

    Ondina D.F.'s Avatar

    What’s happening in the onRegister() method of your mediators? Can you show us at least that fragment of your code? Are you doing more than just adding events listeners?

  5. Support Staff 5 Posted by Ondina D.F. on 11 Jan, 2012 04:52 PM

    Ondina D.F.'s Avatar

    I was in the middle of building a simple flex application using states that I intended to let you see, but then I spotted Shaun’s example : FlexyStates.fxp

    It may help you.

  6. 6 Posted by PJ on 13 Jan, 2012 04:45 PM

    PJ's Avatar

    I got solution for it,
    I mediator i was applying listeners to uicomponents by addEventListener . Rather than doing that i am now using eventMap.mapListener to addlisteners to view children in mediators and override method:

               override public function onRemove():void

    This is working fine.Attaching sample App which illustrates the diffrence

  7. 7 Posted by Stray on 13 Jan, 2012 04:52 PM

    Stray's Avatar

    Hi PJ,

    eventMap.unmapListeners is done by the mediator already, so you don't need to override that function - just as long as you use eventMap.mapListener to the view children, it'll get cleaned up automatically.

    I'm glad you fixed it,


  8. Ondina D.F. closed this discussion on 10 Feb, 2012 11:55 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