When I destroy my objects that are on the stage. I usually just removeChild(this) and I remove event listeners of the object. is this all I need to do to completely remove the object ??
A:
It depends of what you have into the class you used, if it's a loaded class you have to unload it, if you have variable that hold reference to other DisplayObject
you should null them, etc...
Patrick
2010-01-07 20:23:06
removing from stage, and setting them to null. would that remove eventlisteners as well
numerical25
2010-01-07 22:11:10
No you will have to remove event listener
Patrick
2010-01-07 22:39:44
Though you could create your event listeners with weak references that allow for the object to be garbage collected in the event that the event listener is the last hold on the object.
Tegeril
2010-01-08 15:16:53
+2
A:
Yes... sort of.
In AS3 you can not destroy objects. All you can do is remove all references to them, which makes them available for garbage collection. The next time the GC is ran, it will destroy them if they are available. It's a pretty big subject, but basically, always remember to remove all references and you will be going in the right direction.
Keep in mind also, that code can still be executed in objects that are available for GC, sort of odd, but it is important to note.
Tyler Egeto
2010-01-07 20:48:53
do everything you need to to remove all references. That includes removing them from the display object. If you want to know in detail how it works then checkout http://www.gskinner.com/blog/archives/2006/06/as3_resource_ma.html
Allan
2010-01-07 23:03:53
Alan posted a great link, check that out. But yes, definitely remove from the display list, and null out any references. Make sure you stop and timers, and remove event listeners too!
Tyler Egeto
2010-01-08 04:23:20
Just to be clear, the universal answer is "remove all references to the object". The side-answer is, if an object is in the display list, its parent keeps references to it, so removing it from the display list is necessary to remove all references to it.
fenomas
2010-01-09 06:26:14