Reputation: 15018
Yesterday when playing a game (Balloons Tower Defense 3) I noticed that the game started to slow down over time and then randomly speed up very quickly. Looking at the memory usage dropping each time I assumed it was the GC running.
As a legitimate question, is there anyway to force Flash to GC from, say, Firefox? Perhaps there's an addon or a command you can run that will do this? I know that you can do System.gc() but this game isn't mine so I can't modify the source with a "Click here to GC" button.
Upvotes: 3
Views: 534
Reputation: 18860
as far as i know, there's no way to force GC in actionscript. not from the code itself or the surrounding browser.
* edit *
ok, there's a way - but you shouldn't use (and can't in the release version of the flashplayer) it.
more, here: Force Garbage Collection in AS3?
Upvotes: 1
Reputation: 4962
There isn't a way, and really that's not what you need anyway. Forcing the GC to run will actually make things worse. Those random slowdowns you see might actually be the GC running already.
The way you eliminate those slowdowns is to program in such a way that you are never allocating or deallocating memory inside an update function. Make all the references you need up front, never null anything (as that makes it available for collection), and always reuse objects while in the main game loop. There's plenty of time after the game is over to cleanup or re-instantiate.
Upvotes: 4