From another list:

Just to be clear: even if you have no references to a Timer, as long
as the timer is running, it will not be Garbage Collected (think of
it as if the runtime was keeping a reference to running timers).

by Arno Gourdol on the Adobe AIR Team

Keith Peters
[EMAIL PROTECTED]



On Feb 20, 2008, at 10:54 PM, iiley wrote:

Hi guys,

Sorry if you feel this is off-topic, but this test is really interesting, i can't find another better list to discuss this. Here should be some guru can know the right theory.

See the test code below, you guess/think how many times "trace(h.name)" will be invoked? How long the h.handler will be alive? Notice, twe addEventListener call i used "useWeakReference=true". Try to run this test, is your gussing right? Why you are wrong/ right? (My guess is wrong and i don't know why :<)
package {

import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.net.LocalConnection;
import flash.utils.*;

public class TestDic extends Sprite{

 public function TestDic(){
  var timer:Timer = new Timer(500, 10);
  timer.addEventListener(TimerEvent.TIMER, function(e:*):void{
   trace(h.name);
  }, false, 0, true);
  timer.start();

  var h:Handler = new Handler();
  h.name = "Test handler : ";
  stage.addEventListener(MouseEvent.CLICK, h.handler, false, 0, true);
 }
}
}

class Handler{

 public var name:String;

 public function handler(e:*):void{
  trace(e);
 }
}



--
iiley
AsWing http://www.aswing.org
Personal http://www.iiley.com
_______________________________________________
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