in the following code is the garbage collector able to kill the timer or is there any magic that prevents flash player from doing so?
private function initTimer():void
var timer:Timer = new Timer(1000, 0); // repeat forever
timer.addEventListener(TimerEvent.TIMER, tickHandler); // no weak reference
Since the timer is local to initTimer() i assume the garbage collector may clean the timer sooner or later.
It should go away unless you call start(), then the player hooks up an OS
timer to it and it won't go away.
This means, to break the lock of the Timer object we have to
- explicitly call stop()
- wait until the timer has reached its repeatCount == currentCount (aka TimerEvent.TIMER_COMPLETE)
- ohters? (for example remove all event listeners?)
Is this kind of locking a general approach? What about other classes?
var fileReference:FileReference = new FileReference(); // in local scope
urlLoader = new URLLoader(); // in local scope
However i do not plan to take advantage of this kind of internal locking instead i try to hold the reference for the duration of the operation. But i am interested in what one need to do to allow flash player to work best (and keep memory usage low).