11-18-2010 12:40 PM
If I do a removeChild on a button, does that remove the EventListener or do I have to do that first?
Solved! Go to Solution.
11-18-2010 12:51 PM - edited 11-18-2010 12:52 PM
Good question. I always do a removeEventListener on objects being removed. It would be hard to test if the object generating the event is no longer there. I do know in dealing with modules, that if there is still any kind of link associated with the module (eg event listeners), the the module does not totally unload. My guess is that the listener will still be there. I wish there was a "removeAllEventListeners()" to an object, but the safe bet is to remove the listeners before hand.
I think there is a call to return the number of listeners for a particular event, but you kind of want the opposite - number of event generators for a particular event method.
If some knows better, would love to know.
11-18-2010 01:20 PM
according to the ASDocs:
using the removeChild() function simply sets the child objects parent property to null and "unlinks" it from the parent object by setting the value to null. so the object is still floating around just without a parent object and is therefore eligible for garbage collection. however if there is an eventlistener on the child being removed i do not think it can be garbage collected since there is still an active reference to that object even though it is not visible. i think it is confirmed by this line from the doc:
"...the object is garbage collected if no other references to the child exist."
its always good practice though to have your own dispose() function on a class that removes any listeners and sets the object to null. the garbage collection in actionscript isnt flawless so i think they recommend you reuse objects instead of trying to remove them and creating more later.