I had a similar situation, and it made me go crazy for a couple of hours. The answers I found on the net didn't help either, but in the end I found that calling System.gc() does the trick.
I use the weak listening operator ENTER_FRAME to check if the GC instance is being deleted. If the GC clears the object, ENTER_FRAME should stop working.
Here is an example:
package { import flash.display.Sprite; import flash.events.Event; import flash.system.System; import flash.utils.getTimer; import flash.utils.setTimeout; public class GCTest { private var _sprite:Sprite; public function GCTest():void { this._sprite = new Sprite(); this._sprite.addEventListener(Event.ENTER_FRAME, this.test, false, 0, true); setTimeout(this.destroy, 1000);
When you comment out System.gc(); , the test method continues to receive a call even after the destroy method is called (so that the timeout is complete). This is probably due to the fact that there is still enough memory, so the GC does not push itself. When you comment on setTimeout, the test method will not be called at all, then setTimeout is definitely a problem.
Call System.gc(); will stop sending ENTER_FRAME.
I also did some tests with clearTimeout, setInterval and clearInterval, but this did not affect the GC.
Hope this helps some of you with the same or similar problems.
source share