Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I had a similar situation and it drove me crazy for a couple of hours. The answers I found on the net didn't help either but eventually I found that calling <code>System.gc()</code> does the trick.</p> <p>I use a weak reference ENTER_FRAME listener to test if the instance gets removed by the GC. If the GC clears the object the ENTER_FRAME should stop running.</p> <p>Here is the example:</p> <pre><code>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); //TEST doesn't work } private function test(event:Event):void { trace("_" + getTimer()); //still in mem } public function destroy():void { trace("DESTROY") System.gc(); } }} </code></pre> <p>When you comment out <code>System.gc();</code> the test method keeps getting called even after the destroy method was called (so the timeout is done). This is probably beacause there is still enough memory so the GC doesn't kick in by it self. When you comment out the setTimeout the test method won't be called at all meaning the setTimeout is definitely the problem.</p> <p>Calling the <code>System.gc();</code> will stop the ENTER_FRAME from dispatching.</p> <p>I also did some tests with clearTimeout, setInterval and clearInterval but that had no effect on the GC.</p> <p>Hope this helps some of you with the same or similar problems.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload