Anonymous functions are BAD.
So if I am following along correctly here, what I believe is happening is
that because of the anonymous function in the timer handler, the GC doesn't
have a reference to clean up. If you change from an anonymous function and
define the function you get much better results. See my example below. It
calls the tick function 10 times and after that the click handler is cleaned
up. Change back to the anonymous handler and it isn't.
*Steve Mathews*
*Senior Software Engineer*
*Flypaper Studio, Inc.*
www.flypaper.net
package {
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.utils.*;
public class reftest extends Sprite{
public function reftest()
{
var timer:Timer = new Timer(500, 10);
timer.addEventListener(TimerEvent.TIMER, tick, false, 0, true);
/*timer.addEventListener(TimerEvent.TIMER,
function (e:TimerEvent):void{trace("Anonymous tick");},
false,
0,
true);
*/
timer.start();
var h:Handler = new Handler();
stage.addEventListener(MouseEvent.CLICK, h.handler, false, 0, true);
}
private function tick(e:TimerEvent):void
{
trace("tick");
}
}
}
import flash.events.MouseEvent;
class Handler{
public function handler(e:MouseEvent):void
{
trace(e);
}
}
On 2/21/08, iiley <[EMAIL PROTECTED]> wrote:
>
> Thanks Keith, the statement from Adobe is very helpful.
>
> And you are right for your test, because your timer is created by "*new
> Timer(30);"*
> Do you see our original test, the timer is created by "*new Timer(500,
> 10)"*
> That means, after 5 seconds, the timer will not be running, it's not same.
>
> And, then i did more test with some modification of my original test, see
> below, some times, the click handler will be collected now, especially you'v
> clicked before the killing, if you'v not clicked, after twice killing, the
> click handler is still active, now i just can guess -- the GC is really very
> non-predictable, maybe, for some handler, we'd better remember to call
> removeEventHandler than with weak reference:
>
>
> 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, 0);
> timer.addEventListener(TimerEvent.TIMER, function(e:*):void{
> trace("tick");
> }, false, 0, true);
> timer.start();
>
> var h:Handler = new Handler();
> stage.addEventListener(MouseEvent.CLICK, h.handler, false, 0, true);
> setTimeout(killEm, 2000);
> setTimeout(killEm, 4000);//kill again
> }
>
> private function killEm():void{
> trace("kill.....");
> try{
> new LocalConnection().connect('foo');
> new LocalConnection().connect('foo');
> }catch (e:*){}
> }
> }
> }
>
> class Handler{
> 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