ActionScript Clean Up
i want to deallocate a sp开发者_运维问答riteClass from memory and remove it from the display list.
when the spriteClass is instantiated, it creates some of it's own sprites with new tweens and tween events and add them as children. i understand that the tween events must be removed in order for the spritClass to become available for garbage collection, and only afterwards should i remove and nullify the spriteClass, but should i also nullify and remove the spriteClass's sprite children and tweens as well, or does it not matter?
essentially i'd like to know if by writing
spriteClass.deallocate(); //removes it's tween event listeners;
removeChild(spriteClass);
spriteClass = null;
it automatically removes all of it's added children and new instantiations like tweens, sprites, rects, whatever, or am i responsible for removing them all along with event listeners from within my spriteClass.deallocate() function?
As far as I'm aware, any child sprites should not need to be nulled to trigger garbage collection as long as there aren't any references to them from elsewhere.
However, you would need to remove any listeners on the children assuming they are not weakly referenced (an optional argument to addEventListener).
Also for reference, you can check yourself if the garbage collector is doing its job with the Flash Builder Premium profiler (http://help.adobe.com/en_US/flashbuilder/using/WS6f97d7caa66ef6eb1e63e3d11b6c4d0d21-7e46.html)
P.S. You can use the Flash Builder IDE even if its a pure AS3 or Flash project.
精彩评论