tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/104-concerning-removing-event-handlers-etcRobotlegs: Discussion 2018-10-18T16:35:10Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/12716882010-03-20T18:35:51Z2010-03-20T18:35:51ZConcerning removing event handlers, etc? <div><p>Ok, I should have looked more closely to the forum discussion
since this link here described a lot of what I need to know:</p>
<p><a href=
"http://knowledge.robotlegs.org/discussions/questions/84-killing-views">
http://knowledge.robotlegs.org/discussions/questions/84-killing-views</a></p>
<p>I do have a question though... in the example from the link
above it mentions doing the following in a 'remove' method on the
view which can be called from its mediator:</p>
<pre>
<code>if ( parent.contains(this) ) parent.removeChild(this);</code>
</pre>
<p>On a Flex forum I heard that just removing a component from the
display isn't enough and you have to remove it and set it to null
as well? Is this not true?</p>
<p>But now here is my quandary..</p>
<ul>
<li>If I iterate over my views and call remove() on them which in
turn removes them from the parent component (and sets the component
to null), how could I then remove any listeners I added to the view
from the mediator in the mediator preRemove method, since I just
set the view to null? Am I able to do the latter since as soon as I
do parent.removeChild(), that will trigger the view's mediator
'preRemove' so that I could then remove any events I manually
attached to the view in the mediator? I'm still fuzzy on the best
practice here.</li>
</ul>
<p>Basically I have some event listeners add to view components
directly in the mediator and some added to components directly
within my mxml view as well. What's the order in how I should clean
this up when I need to remove the view from its parent
container?</p>
<p>Thanks again.</p></div>rickcrtag:robotlegs.tenderapp.com,2009-10-18:Comment/12716882010-03-20T18:44:16Z2010-03-20T18:44:16ZConcerning removing event handlers, etc? <div><p>I like to add a dispose method on my views (I implement an
interface IDisposable) which does any cleanup that needs to happen.
Typically this means nulling references, cleaning up binding,
calling dispose() on children, and removing any listeners. With
this approach your mediator simply needs to call
view.dispose()...</p></div>Joel Hookstag:robotlegs.tenderapp.com,2009-10-18:Comment/12716882010-03-20T19:52:19Z2010-03-20T19:52:19ZConcerning removing event handlers, etc? <div><p>I'm curious, what about just doing all that in the mediator's
remove or preRemove? This way you can also remove any listeners you
manually added to view components directly from your onRegister in
the mediator? Sometimes I'm attaching listeners to the view
directly within the mediator so I need to remove them as well
there. (At least I 'think' I do.. the whole issue of GC and event
listeners is still vague in my mind.)</p></div>rickcr