views:

75

answers:

2

Hi If you're removing a MovieClip from the display list, and that MovieClip in turn has child MovieClips which have their own event listeners, is it necessary to remove ALL listeners from the child MovieClips?

or just the parent MovieClip that is being directly removed from the display list?

A: 

I think is enough to removeChild(MC), then MC=null or delele MC, I guess delete will do the work id you read the specifications from Adobe, I think you can also call System.gc but this is for AIR apps.

Ionel Crisu
Usualy `delete` is used to remove dynamic properties from an object. Although it deletes a reference to the content of the property, it is unusual to use it because it has a very specific scope and use. http://livedocs.adobe.com/flex/3/langref/operators.html#delete
LopSae
+1  A: 

It depends if the listeners attached, to either the parent or children MovieClips, have weak references pointing to it or not.

When you add a listener, you can use the last parameter to set if the listener will use a weak reference. This is exactly what you need to know for the question you ask.

//This listener will use a weak reference, notice the last "true"
something.addEventListener("event", myFunction, false, 0, true);
//This is called a weak reference listener.
//The ussual listener, with default parameters, is a strong refence listener.

EventDispatcher Reference

So an object will be garbage collected if all the references to such object are deleted. Listeners added with the default parameters count toward those references (since the last parameter default value is false). So having a MovieClip with a strong reference listeners attached to it or any of its children, by removing it from the display list the clip will NOT be garbage collected until the listener references are also deleted (by using the removeEventListener method).

If you use weak references in a clip or any of its children, by removing it from the display list it will eventually be garbage collected. Have in mind that this may occur after some time, so events like ENTER_FRAME may be still be triggered and called until the object is finally collected.

LopSae