all groups > flash actionscript > september 2007 >
You're in the

flash actionscript

group:

Force garbage collection?


Force garbage collection? Lujunq
9/18/2007 6:43:59 PM
flash actionscript:
I'm currently checking memory usage of an script, but even afer deleting
classes, the memory usage does not drop, and even keep icreasing as new
instances are created (and then deleted). I believe thit is because even these
instances being eligible for garbage collection this is not happening because
there's no need to free memory for new instances... How often garbage
collection happens? Is there a way to force garbage collecion usign AS3 so I
can check if my code is really removing the instances?
Re: Force garbage collection? SymTsb
9/18/2007 7:39:02 PM
Re: Force garbage collection? kglad
9/18/2007 7:52:02 PM
you can use the code below to force garbage collection. (terminate the loop
when no loner needed):



var t:Timer=new Timer(100,0);
t.addEventListener(TimerEvent.TIMER,f2,false,0,true);
t.start();
}

function f2(evt:TimerEvent) {
for (var i:int=0; i<2000; i++) {
this["mc_"+i+"_"+evt.target.currentCount] = new MovieClip();
}
trace(System.totalMemory/1024);
}
Re: Force garbage collection? Ahjin
9/18/2007 7:54:32 PM
I have thought of a kind of garbage collection because I have similar
experience to you.
My case is that my flash application has simulation to test physics rules and
as time goes by, the speed of running the application is getting slow. I also
checked how much memory was used and recognized that it used almost all memory
of my notebook after several minutes. I think that's a problem of flash in my
opinion.



Re: Force garbage collection? GWD
9/18/2007 7:55:19 PM
Grant Skinner has info on an unsupported way to do it (not recommended for
production use as it may not work in future - or latest release - flash
players), plus a lot of good background info.

Check out:
[b]Unsupported Way to Force GC[/b] in this page:
http://www.gskinner.com/blog/archives/2006/08/as3_resource_ma_2.html
Re: Force garbage collection? kglad
9/18/2007 8:03:49 PM
Re: Force garbage collection? GWD
9/18/2007 8:12:05 PM
@kglad: oh,ok. I had read it the article some time ago and just had it floating
around in my head somewhere. Sounds like those neurons should be recycled.
I had thought it might still be (assuming it was ever) relevant, although I
hadn't tried it myself.

-Strike that suggestion then. -
Re: Force garbage collection? kglad
9/18/2007 8:30:44 PM
Re: Force garbage collection? Lujunq
9/18/2007 8:59:53 PM
Re: Force garbage collection? kglad
9/18/2007 10:20:14 PM
each iteration of that loop consumes memory and the more memory consumed the
more likely flash will trigger gc.

so, it's a crude way to trigger gc, but unfortunately there is no elegant way.
i think this is a problem that will hopefully be fixed in a flash update.
AddThis Social Bookmark Button