first defined a class:
class C1 extends Sprite
{
public function C1() { super(); }
}
then write the following codes in Document Class:
setInterval(function(a:Sprite):void {
a.addChild(new C1());
}, 10, this);
setInterval(function(a:Sprite):void {
a.removeChildAt(0);
}, 11, this);
then run it and check the memory ustage, it will get more and more larger…
how could released the memory when remove the child from root?
The Flash VM uses garbage collection to free up memory. GC will be executed at arbitrary times by the player, unless you explicitly call
System.gc(), but this method is available in AIR and the debugger version of Flash Player only. Therefore, usage of memory might still continue to increase, even though you have freed up resources in your program, until the GC process is executed.Also, note that
addChild()andremoveChild()merely add and remove items to and from the display list. To really free up a resource, you have to explicitly set all references to it retained in your program tonull.