Removing event listeners before closing a module
I add an instance of this module to the dispay list and then remove it. Will the event listener attached to foo create a leak? A simplified module:
<s:Module creationComplete="init()">
<fx:Script>
protected var foo:Bar = new Bar();
protected function init() {
foo.addEventListener(MouseEvent.CLICK, foo_clickHandler);
}
protected function foo_clickHandler(ev开发者_如何学Cent:MouseEvent):void {
//do something
}
</fx:Script>
</s:Module>
This module does not have memory leaks since you add listener to a local object, not to a Stage
, StyleManager
or some other global-accessible stuff.
It will. You should remove the listener, or use weak references when creating the listener.
foo.addEventListener(MouseEvent.CLICK, foo_clickHandler, false, 0, true);
精彩评论