1
votes

I have a movieclip in library that has a button inside it. Assume that I had added an eventListener to the nested button after adding the movieclip to the stage . Will this listener be automatically removed when I remove the element using removeChild? Is it necessary to use removeEventListener even after removeChild is called?

2

2 Answers

2
votes

If you add the event listener using a weak reference (last parameter to addEventListener I believe) it should be cleaned up. Take care however as this may clean the event listener before you want it to, for instance when going out of scope of wherever the listener was declared.

If it's not a weak reference, you need to clear the event listener yourself as otherwise this means there's a reference to your element and you will have a memory leak.

1
votes

Make sure to use weak referencing - this is one of the memory leaks in AS3 - GSkinner has a great explanation at http://gskinner.com/blog/archives/2006/07/as3_weakly_refe.html