Reputation: 19338
Quick question; should I use removeChild()
or removeEventListener()
first?
Also, if I set an object to null
, do I still need to remove event listeners from that object?
Upvotes: 0
Views: 388
Reputation: 13151
"Remove event listeners before removeChild."
Whether doing the other way will throw an error or not, totally depends on the event you are listening to & the objects you are trying to access after the event fires.
But it always a good practice to remove event listeners as fast as you can.
For example : If you require the click of a button once & you seem to disable the button after click, It doesn't make sense to keep the listener running.
addEventListener(MouseEvent.CLICK, clicked, false, 0, true);
Which hints the garbage collector to remove the listener when object is set to null.
Upvotes: 3
Reputation: 39466
Should I remove all the eventListener before removeChild, or removeChild before eventListener.
These tasks are unrelated, so it doesn't matter. That said, there are some events which are triggered by removing a child, so if you're relying on Event.REMOVED_FROM_STAGE
, then you'll want to remove the event listener AFTER.
If I set an object to NULL, do I still need to removeEventListener?
Yes.
Upvotes: 1