|
-
Should you keep removing addEventListener???
Hi guys,
When i add this:
Actionscript Code:
bob.addEventListener(MouseEvent.ROLL_OVER,funCtion);
And many others --
Should i keep removing them when they are not going to be used -- then re-add them when they are needed again.
Or can i just leave them - and they will not take up any extra resources?
In as2 -- if had on(release) on a button -- i woudlnt have to keep removing it - so i'm just seeing if i have to do it in AS3 with listeners?
Thanks for the help!
-
I'm assuming you want to disable the handler. If you don't, then there's no reason to remove it. If you do want to disable it, you can either remove the handler as an event listener, or you can set a variable which you check for in the handler and immediately exit. Removing the handler will mean that the function is not even executed, so that's almost always more efficient. But if your logic for when to enable/disable the handler is complex, a state variable might be simpler to understand.
-
Simple is this, that if your listener is for a display object which is in the displayList, its no need to remove it. If it is for a Events and no need to keep it after executing the event, remove it. In case of adding ADDED_TO_STAGE Listener ..... remove on the execution function.
So, all it depends on how you execute your application and what need to keep it run.
poltuda
-
Lifetime Friend of Site Staff
Not removing them may seem harmless but if you've ever wondered why your app is "leaking" memory you can stop blaming Flash... The listener ceates a reference to the object it's added to. If you want the garbage collector to clean up "unused" objects they can't have ANY references hanging around.
When your swf2exe tool just HAS to work
there's only one choice... SWF Studio
-
Senior Member
The easy rule is if you are finished using it then remove it otherwise keep it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|