tag:robotlegs.tenderapp.com,2009-10-18:/discussions/robotlegs-2/11293-child-sprites-mediators-are-never-destroyed-they-keep-catching-events-from-contextRobotlegs: Discussion 2014-07-11T08:10:04Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/334822952014-06-20T16:05:34Z2014-06-20T16:12:21ZChild sprites' mediators are never destroyed, they keep catching events from context!<div><p>Hi,</p>
<p>Thanks for showing some code and for explaining the workflow!
That's always a good idea when asking a question, but not everyone
does that:)</p>
<blockquote>
<p>The question is that when I remove the parent view from the
stage, should I expect the child view's mediator to be
destroyed?</p>
</blockquote>
<p>The answer is Yes, if the child view has been removed from stage
as well.<br>
But if there are still references to views and/or mediators they
will be kept alive.</p>
<blockquote>
<p>I want the SpeedPanelMedatior matched to my SpeedPanel object to
be destroyed when the CarView gets removed from the stage.</p>
</blockquote>
<p>Normally, SpeedPanel would be removed from stage when CarView
gets removed.</p>
<p>First thing to check is if SpeedPanel has been indeed removed
from stage and garbage collected. Use something like Flash Builder
profiler to find loitering objects and which class has a reference
to another class.(don't forget to force the gc if you use the
profiler)</p>
<p>If SpeedPanel is still there, look at what could keep it alive.
Look at this discussion for details:<br>
<a href=
"http://knowledge.robotlegs.org/discussions/robotlegs-2/8306-old-mediator-is-not-removed-flex#comment_30208850">
http://knowledge.robotlegs.org/discussions/robotlegs-2/8306-old-med...</a></p>
<p>In your SpeedMediator you have this line:<br>
injector.injectInto(view);<br>
What are you injecting into the view?</p>
<p>Are you using as3-signals? If yes, don't forget to remove their
listeners!!</p>
<blockquote>
<p>I am able to achieve this manually by removing SpeedPanel from
the CarView (ex: carView.removeChild(speedPanel). Is that the way
it is?</p>
</blockquote>
<p>It is a good idea to have a destroy()/clean() method inside of
views, that takes care of removing all possible references to the
view in order for it to get garbage collected.<br>
So, yes, you can do that, but first try to see what's keeping it
alive.</p>
<blockquote>
<p>Well if the answer of this question is a YES, then I have a
problem. If it is a NO, is there an option to turn this on or
should I remove each children of this parent view from the stage
one by one?</p>
</blockquote>
<p>Maybe I misunderstood your question? I'm not sure what you want
to be kept alive and what should get destroyed. Do you want to
manually mediate/unmediate views?</p>
<p>In case you can't find a solution, try to reproduce the issue in
a bare-bone project, where you have only the 3 views/mediators in
question. If you want, you can attach the simplified app as a zip
and I'll take a look at it. Also, try your scenario with simple
Sprites that don't extend a Starling sprite. Maybe Starling is the
culprit ;) Are you using one of the Starling extensions for
robotlegs?</p>
<p>Let me know how it goes.</p>
<p>Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/334822952014-06-23T13:59:40Z2014-06-23T14:15:18ZChild sprites' mediators are never destroyed, they keep catching events from context!<div><p>Hi Ondina,</p>
<p>Thank you for your reply. I have found a solution, yay! Let me
answer some of your questions to clarify the case here:</p>
<p>I am using as3-signals, I remove their listeners carefully.<br>
injector.injectInto(view); This line is for PostConstruct.</p>
<p>I am using SARS (Starling extension for robotlegs).</p>
<p>Well after some investigation and debugging about mediators I
ended up with the MediatorManager.as class of robotlegs and I
realized that Event.REMOVED_FROM_STAGE listener is added to every
flash DisplayObject in the addMediator function. Since I use
starling DisplayObject these listeners which are responsible for
destroying the mediators are never added. Let me put the
corresponding code snippet here:</p>
<pre>
<code>public function addMediator(mediator:Object, item:Object, mapping:IMediatorMapping):void
{
const displayObject:DisplayObject = item as DisplayObject;
// This if statement never becomes true, since my display objects are starling display objects
if (displayObject && mapping.autoRemoveEnabled)
displayObject.addEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);
// Synchronize with item life-cycle
if (itemInitialized(item))
{
initializeMediator(mediator, item);
}
else
{
displayObject.addEventListener(CREATION_COMPLETE, function(e:Event):void
{
displayObject.removeEventListener(CREATION_COMPLETE, arguments.callee);
// Ensure that we haven't been removed in the meantime
if (_factory.getMediator(item, mapping) == mediator)
initializeMediator(mediator, item);
});
}
}</code>
</pre>
<p>Well I supposed that SARS should have resolved this issue, after
some investigation I found out that SARS is not aware of children
sprites that are removed.</p>
<p>So I decided to fork your MediatorMap extension and changed
imports from flash.display.DisplayObject to
starling.display.DisplayObject :)</p>
<p>For now everything works like a charm.</p></div>ikbalnamlitag:robotlegs.tenderapp.com,2009-10-18:Comment/334822952014-06-27T08:19:19Z2014-06-27T08:19:19ZChild sprites' mediators are never destroyed, they keep catching events from context!<div><p>Sorry for the delay in replying.</p>
<blockquote>
<p>Well I supposed that SARS should have resolved this issue, after
some investigation I found out that SARS is not aware of children
sprites that are removed.</p>
</blockquote>
<p>I have no idea whether Vjekoslav is still maintaining the SARS
project, but trying to open an issue on github wouldn't hurt:)</p>
<p>I'm not familiar enough with SARS and Starling to be able to see
if there is a better solution to your problem, especially one that
doesn't require changing robotlegs' classes.</p>
<p>But, who knows, maybe the solutions I presented in the
discussion mentioned below could inspire you, despite my
Starling-newbiness ;)</p>
<p><a href=
"http://knowledge.robotlegs.org/discussions/problems/3815-injector-is-missing-a-mapping-to-handle-injection-into-property#comment_28966371">
http://knowledge.robotlegs.org/discussions/problems/3815-injector-i...</a></p></div>Ondina D.F.