Absolutely. I would never, ever, ever, rely on the GC to clean up any
event listeners.
ever.
Keith Peters
[EMAIL PROTECTED]
On Feb 21, 2008, at 10:55 AM, slangeberg wrote:
the GC is really very non-predictable, maybe, for some handler, we'd
better remember to call removeEventHandler than with weak reference
I'd say you hit it on the head, there! The weak references serve
more as a convenience, in my mind. Those 'addListener' references
can / often are very pervasive, and you'd best remove them manually,
if it's code that imposes any performance hit.
On Thu, Feb 21, 2008 at 2:30 AM, 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
--
: : ) Scott
Helping your grandma on the interweb
at: http://blog.criticalpile.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