Mediators Garbage collection issue

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. 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.

    Ondina

  2. Ondina,
    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. Could you attach a stripped out example exhibiting the issue or paste some relevant code. I will take a look at it.

  4. 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. 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

    http://knowledge.robotlegs.org/discussions/questions/114-best-use-o...

    It may help you.

  6. 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
        {    
            eventMap.unmapListeners();
        }
    

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

    • Test.zip (available to support staff) 69.9 KB
  7. 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,

    Stray

  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

Generic

? 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