Rich,

It's probably too late for me to be trying to make sense of this, but  
yes, a weakly-referenced listener for most objects will be garbage  
collected eventually, as long as no other reference remain. Here, the  
timer is a local variable, and has a weak reference, so one might  
think, hey, there is no more reference, it should be cleaned up. Of  
course, WHEN, it would be cleaned up is anybody's guess. But, as I  
illustrated in this post:

http://www.bit-101.com/blog/?p=1169

it's NEVER going to get cleaned up. The system itself retains a ref to  
the timer as long as it's running. This is different than a sprite or  
mc running an enterFrame handler, which will eventually get cleaned up  
if there are no refs to it.


Keith Peters
[EMAIL PROTECTED]



On Feb 21, 2008, at 1:39 AM, Rich Shupe wrote:

> Keith, isn't the issue here more that the timer and stage references  
> remain?
> That is, that weak references only free up an object for later  
> collection if
> there is no other reference, but aren't the same as removing a  
> listener?
>
> For the running timer to be the issue, wouldn't the timer reference  
> have to
> be nullified prior to the 10th trace?
>
> The code at the end of this email is a hastily adapted example (best
> practices not assured) that I think illustrates the timer-running  
> issue. If
> the third line of the onTimer() method remains commented, all ten  
> traces
> occur even after the timer object is nullified, illustrating Arno's
> description. If the line is uncommented, the trace ceases after four
> occurrences, as expected, because the timer was stopped first.
>
> In the original example, however, isn't the fact that the trace  
> occurs 10
> times, and the click remains active, due to the fact that the  
> references
> remain?
>
> Rich
>
> package {
>
>    import flash.display.Sprite;
>    import flash.events.MouseEvent;
>    import flash.events.TimerEvent;
>    import flash.utils.*;
>
>    public class TestDic extends Sprite {
>
>        public var timer:Timer;
>        private var n:int = 0;
>        private var h:Handler;
>
>        public function TestDic() {
>            timer = new Timer(50, 10);
>            timer.addEventListener(TimerEvent.TIMER, onTimer,
>                                   false, 0, true);
>            timer.start();
>
>            h = new Handler(this);
>            h.name = "Test handler: ";
>            stage.addEventListener(MouseEvent.CLICK, h.handler,
>                                   false, 0, true);
>
>        }
>
>        private function onTimer(e:*):void {
>            trace(n);
>            if (n >= 3) {
>                //timer.stop();
>                timer = null;
>                h._timr = null;
>            }
>            trace(h.name);
>            n++;
>        }
>    }
> }
>
> class Handler {
>
>    import flash.utils.Timer;
>    import flash.events.MouseEvent;
>
>    public var name:String;
>    public var _timr:Timer;
>
>    public function Handler(p:*) {
>        _timr = p.timer;
>    }
>
>    public function handler(e:MouseEvent):void {
>        trace(e);
>        if (_timr != null) {
>            _timr.start();
>        }
>    }
> }
>
>
>
> _______________________________________________
> osflash mailing list
> [email protected]
> http://osflash.org/mailman/listinfo/osflash_osflash.org


_______________________________________________
osflash mailing list
[email protected]
http://osflash.org/mailman/listinfo/osflash_osflash.org

Reply via email to