Mediator being destroyed but still existing in new context
hi,
I have a shell context to which I alternatively add two
contexts. When I switch contexts, I remove one of them and add the
other.
Removing a context seems to go well in the stack trace. The
destroy() function is being called also of the mediators onto which
child views are mapped. For instance:
32167 INFO Context-4-85 Context-4-85 Destroying...
32171 INFO Context-4-85 Context-4-85 Destroy complete
32172 INFO Context-0-50 Context-0-50 Removing child context Context-4-85
I also remove the context from the view manager
while(viewManager.containers.length >0)
viewManager.removeContainer(viewManager.containers[0]);
Then I add the other context. The problem is that the mediator of
the previous context, and also the mediators mapped to the child
views are still alive! They are not being initialized again, but
they listen to signals send to them. Btw, I also have the mediators
in the new context listen for these signals, which are dispatched
from the shell context.
I thought maybe it has to do with that I'm working with two stage (two native windows) but I also remove all the children from both stages when switching modules.
Could this be a bug or am I doing something wrong?
thanks,
Jeff.
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
Support Staff 1 Posted by Ondina D.F. on 24 Jul, 2013 12:17 PM
First thing you should check is if the mediated views are removed from stage and gc-ed.
Try to remove the views inside a window in a test method (without closing the window)
If you're using FlashBuilder, you can watch the view and its mediator in the Flash Profiler.
If after pressing the gc button, the view (and/or the mediator) is still there, then you have to check what's keeping it alive. See if you need to remove event listeners and/or signals, that might have a reference to the view (inside your view or/and the mediator) .
If that's not the problem, then maybe the window doesn't remove the view automatically when you close it.
Support Staff 2 Posted by creynders on 24 Jul, 2013 12:26 PM
You need to manually unsuscribe the mediators from their signals in the
mediator's `destroy` method.
3 Posted by JeffW. on 24 Jul, 2013 02:40 PM
I'm not closing windows, they always stay open, I just remove contexts from their stages.
I now remove all signals and modular connector events in the destroy() methods of the mediators. Something like this:
I did another check on listeners in the view, they all are being removed.The mediators are still there in the new context, also after garbage collecting in the profiler.
Should I also unmap signals from commands that mediators are listening for and remap them in the new context? These are dispatched from the shell context and used in both modules.
4 Posted by JeffW. on 24 Jul, 2013 02:55 PM
I'm not seeing the mediators been called in my stack trace anymore, that's good. But that's because I removed the listeners. But still seeing the mediators as live objects in the profiler, also after gc-ing.
Support Staff 5 Posted by Ondina D.F. on 24 Jul, 2013 02:58 PM
I'm not sure I understand if you mean that the mediators instances== 0 in the profiler or not?
Support Staff 6 Posted by Ondina D.F. on 24 Jul, 2013 03:00 PM
Just saw your last message.
Hmm, something is keeping them alive, obviously.
7 Posted by JeffW. on 24 Jul, 2013 03:01 PM
Definitely 0!
Sorry, not very familiar with the profiler, but I already love it. So that means the mediators are officially gone?
8 Posted by JeffW. on 24 Jul, 2013 03:02 PM
Or are they still alive even when they have 0 instances?
Support Staff 9 Posted by Ondina D.F. on 24 Jul, 2013 03:04 PM
I suggest trying to mediate a very simple view with no additional signals or events or any other stuff. See if that reproduces the odd behavior.
Support Staff 10 Posted by Ondina D.F. on 24 Jul, 2013 03:04 PM
0 means they are gone :)
Support Staff 11 Posted by Ondina D.F. on 24 Jul, 2013 03:05 PM
Are the views 0 too?
12 Posted by JeffW. on 24 Jul, 2013 03:05 PM
Excellent! I started to hate them :)
Yep, the views are 0 too.
Support Staff 13 Posted by Ondina D.F. on 24 Jul, 2013 03:11 PM
and the signals, how are they doing;) Or everything else that should get gc-ed?
Support Staff 14 Posted by Ondina D.F. on 24 Jul, 2013 03:13 PM
You can take memory snapshots, then in the memory snapshot view you can click on a class that wasn't gc-ed and see what's keeping it alive.
If you have 2 memory snapshots you can find loitering objects.
Support Staff 15 Posted by Ondina D.F. on 24 Jul, 2013 03:21 PM
How are you removing the views from a window? And how are you adding them to the new window? Are you sure is not a re-parenting problem? Are you sure that the mediators and views in the new context are the same as the ones removed from the other window?
16 Posted by JeffW. on 24 Jul, 2013 03:23 PM
I only see instances of objects I need in that context. But some signals have two instances, which makes sense because I'm not using one module per 'round' but two (both can be 'slave' and 'master'). When is a signal being instantiated? The moment it is being injected or the moment it is being dispatched?
17 Posted by JeffW. on 24 Jul, 2013 03:27 PM
I'm not reparenting anymore. I remove views/contexts in the shell mediator:
But I think I'm good, no instances of unwanted objects at this moment.18 Posted by JeffW. on 24 Jul, 2013 03:29 PM
'The moment it is being injected or the moment it is being dispatched?'
I meant 'the moment it is being mapped'
And I think that's the moment?
Support Staff 19 Posted by Ondina D.F. on 24 Jul, 2013 03:33 PM
You'll see an instance of a signal in your profiler the moment it is injected into a class, or the moment you do new SomeSignal().
Support Staff 20 Posted by Ondina D.F. on 24 Jul, 2013 03:34 PM
So, problem solved?
21 Posted by JeffW. on 24 Jul, 2013 03:35 PM
For now it sure seems to be! Up to the next one!
I really would like to thank you and also creynders for your incredibly great and fast support :)
Support Staff 22 Posted by Ondina D.F. on 24 Jul, 2013 03:42 PM
Awsome!
You're welcome, Jeff :)
You can close the discussion, I guess.
Till next time, then.
JeffW. closed this discussion on 24 Jul, 2013 03:42 PM.