I use the setTimeout() function through my application but when its time to garbage collect. the method still runs and calls on a function. How do I stop it from calling on a certain function. I tried setting it to null but it doesnt work
相关问题
- garbage collection best practices
- Should I wait for Flash Player 10.1 or go with Fla
- How to load flex swf from flash?
- FlashDevelop Haxe (Flash) debugger
- Converting Date with Time in PST into UTC format
相关文章
- Are there any benefits when using final in AS3?
- Trace on Chrome/Browser console
- as3 ByteArray to Hex (binary hex representation)
- getElementById not working in Google Chrome extens
- Libraries for text animation in Flex / Actionscrip
- About Collision detection alghorithms in AS3
- How to upload BitmapData to a server (ActionScript
- Manage resources to minimize garbage collection ac
Nevermind, clearInterval()!
setTimeout returns an reference to the timeout, which you can then use when you call clearTimeout.
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
System.gc()
does the trick.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.
Here is the example:
When you comment out
System.gc();
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.Calling the
System.gc();
will stop the ENTER_FRAME from dispatching.I also did some tests with clearTimeout, setInterval and clearInterval but that had no effect on the GC.
Hope this helps some of you with the same or similar problems.
See:
clearTimeout()
Ditto. Use "clearInterval(timeoutInstance)".
If you are using AS3, I'd use the Timer() class