As far as I know, this is not documented. I have a feeling that the GC will not work during the execution of your code (i.e., while your code is on the execution stack, each frame, the player creates a new stack to use the code). Obviously, this comes from observation and my own experience with Flash, so I would not say that it is 100% accurate. I hope this is a reasonable guess.
Here is a simple test that seems to show that this is true:
package { import flash.display.Sprite; import flash.net.FileReference; import flash.system.System; import flash.utils.Dictionary; import flash.utils.setTimeout; public class test extends Sprite { private var _dict:Dictionary = new Dictionary(true); public function test() { testGC(); setTimeout(function():void { traceCount(); },2000); } private function testGC():void { var fileRef:FileReference; for(var i:int = 0; i < 100; i++) { fileRef = new FileReference(); _dict[fileRef] = true; traceCount(); System.gc(); } } private function traceCount():void { var count:int = 0; for(var i:* in _dict) { count++; } trace(count); } } }
GC seems especially greedy when there are FileReference objects (again, this is from my experience, this is not documented as far as I know).
Now, if you run the above code, even explicitly calling System.gc() , the objects will not be collected while your function is on the stack: you can see that they are still alive, looking at the dictionary count (which to use for obvious reasons for weak links).
When this counter is traced again, in another execution stack (called by the asynchronous call to setTimeout), all objects were freed.
So, I would say that the GC is not the culprit of the poor work in your case. Again, this is a simple observation and the fact that the GC did not start while the user code was running in this test does not mean that it will never be. This is probably not, but since it is not documented, I do not know, for sure, for sure. Hope this helps.
Juan Pablo Califano
source share