tag:robotlegs.tenderapp.com,2009-10-18:/discussions/robotlegs-2/4172-mediator-being-destroyed-but-still-existing-in-new-contextRobotlegs: Discussion 2013-07-24T15:42:50Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/279316532013-07-24T12:17:16Z2013-07-24T12:17:16ZMediator being destroyed but still existing in new context<div><p>First thing you should check is if the mediated views are
removed from stage and gc-ed.<br>
Try to remove the views inside a window in a test method (without
closing the window)<br>
If you're using FlashBuilder, you can watch the view and its
mediator in the Flash Profiler.<br>
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)
.</p>
<p>If that's not the problem, then maybe the window doesn't remove
the view automatically when you close it.</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/279316532013-07-24T12:26:59Z2013-07-24T12:26:59ZMediator being destroyed but still existing in new context<div><p>You need to manually unsuscribe the mediators from their signals
in the<br>
mediator's <code>destroy</code> method.</p></div>creynderstag:robotlegs.tenderapp.com,2009-10-18:Comment/279316532013-07-24T14:40:30Z2013-07-24T14:42:55ZMediator being destroyed but still existing in new context<div><p>I'm not closing windows, they always stay open, I just remove
contexts from their stages.</p>
<p>I now remove all signals and modular connector events in the
destroy() methods of the mediators. Something like this:<br></p>
<pre>
<code>override public function destroy():void
{
removeContextListener(ModularConnectorEvent.SWITCH_GAME_STATE, onViewRequested, ModularConnectorEvent);
removeContextListener(ModularConnectorEvent.SHOW_WORD, showWord, ModularConnectorEvent);
removeContextListener(ModularConnectorEvent.HIDE_GAME, hideGame, ModularConnectorEvent);
super.destroy();
}</code>
</pre>
<pre>
<code>override public function destroy():void
{
switchGameState.remove(onViewRequested);
showWord.remove(gameView.showWord);
playAnswerIntro.remove( gameView.playAnswerFeedback);
playAnswerOuttro.remove(gameView.playFeedbackOuttro);
gameView.triggerRequested.remove(triggerRequested.dispatch);
gameView.newWordRequested.remove(newWordRequested.dispatch);
super.destroy();
}</code>
</pre>
I did another check on listeners in the view, they all are being
removed.
<p>The mediators are still there in the new context, also after
garbage collecting in the profiler.</p>
<p>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.</p></div>JeffW.tag:robotlegs.tenderapp.com,2009-10-18:Comment/279316532013-07-24T14:55:09Z2013-07-24T14:55:09ZMediator being destroyed but still existing in new context<div><p>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.</p></div>JeffW.tag:robotlegs.tenderapp.com,2009-10-18:Comment/279316532013-07-24T14:58:47Z2013-07-24T14:58:47ZMediator being destroyed but still existing in new context<div><blockquote>
<p>The mediators are still there in the new context, also after
garbage collecting in the profiler.</p>
</blockquote>
<p>I'm not sure I understand if you mean that the mediators
instances== 0 in the profiler or not?</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/279316532013-07-24T15:00:30Z2013-07-24T15:00:49ZMediator being destroyed but still existing in new context<div><p>Just saw your last message.</p>
<blockquote>
<p>But still seeing the mediators as live objects in the profiler,
also after gc-ing.</p>
</blockquote>
<p>Hmm, something is keeping them alive, obviously.</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/279316532013-07-24T15:01:34Z2013-07-24T15:01:34ZMediator being destroyed but still existing in new context<div><p>Definitely 0!</p>
<p>Sorry, not very familiar with the profiler, but I already love
it. So that means the mediators are officially gone?</p></div>JeffW.tag:robotlegs.tenderapp.com,2009-10-18:Comment/279316532013-07-24T15:02:15Z2013-07-24T15:02:15ZMediator being destroyed but still existing in new context<div><p>Or are they still alive even when they have 0 instances?</p></div>JeffW.tag:robotlegs.tenderapp.com,2009-10-18:Comment/279316532013-07-24T15:04:37Z2013-07-24T15:04:37ZMediator being destroyed but still existing in new context<div><p>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.</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/279316532013-07-24T15:04:53Z2013-07-24T15:04:53ZMediator being destroyed but still existing in new context<div><p>0 means they are gone :)</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/279316532013-07-24T15:05:36Z2013-07-24T15:05:36ZMediator being destroyed but still existing in new context<div><p>Are the views 0 too?</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/279316532013-07-24T15:05:54Z2013-07-24T15:05:54ZMediator being destroyed but still existing in new context<div><p>Excellent! I started to hate them :)</p>
<p>Yep, the views are 0 too.</p></div>JeffW.tag:robotlegs.tenderapp.com,2009-10-18:Comment/279316532013-07-24T15:11:36Z2013-07-24T15:24:39ZMediator being destroyed but still existing in new context<div><p>and the signals, how are they doing;) Or everything else that
should get gc-ed?</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/279316532013-07-24T15:13:05Z2013-07-24T15:13:05ZMediator being destroyed but still existing in new context<div><p>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.<br>
If you have 2 memory snapshots you can find loitering objects.</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/279316532013-07-24T15:21:40Z2013-07-24T15:22:26ZMediator being destroyed but still existing in new context<div><p>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?</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/279316532013-07-24T15:23:53Z2013-07-24T15:25:18ZMediator being destroyed but still existing in new context<div><p>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?</p></div>JeffW.tag:robotlegs.tenderapp.com,2009-10-18:Comment/279316532013-07-24T15:27:23Z2013-07-24T15:27:56ZMediator being destroyed but still existing in new context<div><p>I'm not reparenting anymore. I remove views/contexts in the
shell mediator:<br></p>
<pre>
<code>public function removeView():void
{
view.parent.removeChild(view);
}</code>
</pre>
But I think I'm good, no instances of unwanted objects at this
moment.</div>JeffW.tag:robotlegs.tenderapp.com,2009-10-18:Comment/279316532013-07-24T15:29:58Z2013-07-24T15:29:58ZMediator being destroyed but still existing in new context<div><p>'The moment it is being injected or the moment it is being
dispatched?'</p>
<p>I meant 'the moment it is being mapped'</p>
<p>And I think that's the moment?</p></div>JeffW.tag:robotlegs.tenderapp.com,2009-10-18:Comment/279316532013-07-24T15:33:37Z2013-07-24T15:33:37ZMediator being destroyed but still existing in new context<div><p>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().</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/279316532013-07-24T15:34:08Z2013-07-24T15:34:08ZMediator being destroyed but still existing in new context<div><blockquote>
<p>But I think I'm good, no instances of unwanted objects at this
moment.</p>
</blockquote>
<p>So, problem solved?</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/279316532013-07-24T15:35:51Z2013-07-24T15:35:51ZMediator being destroyed but still existing in new context<div><p>For now it sure seems to be! Up to the next one!</p>
<p>I really would like to thank you and also creynders for your
incredibly great and fast support :)</p></div>JeffW.tag:robotlegs.tenderapp.com,2009-10-18:Comment/279316532013-07-24T15:42:07Z2013-07-24T15:42:07ZMediator being destroyed but still existing in new context<div><p>Awsome!<br>
You're welcome, Jeff :)</p>
<p>You can close the discussion, I guess.</p>
<p>Till next time, then.</p></div>Ondina D.F.