removeEventListener causing memory leak?
Update
After inspecting my dispatcher .. i find this awful mistake:
override public function addEventListener(type:String, listener:Function, useCapture:Boolean=false, priority:int=0.0, useWeakReference:Boolean=false):void {
_node.addEventListener(type, listener, useCapture, priority, useWeakReference)
}
override public function removeEventListener(type:String, listener:Function, useCapture:Boolean=false):void {
_node.addEventListener(type, listener, useCapture)
}
(DOH!!!!!!!!!! LOL)
——
To cut to the chase, in my personal AS3 framework, I’ve implemented deconstructors in all my DisplayObjects objects. The deconstructors mostly feature removeEventListener calls as I try to stay away from using weak refs. Today, while making a regular memory leak check using Flex Builder 3’s profiler, I noticed that I had a few DisplayObjects still latched onto an event dispatcher model object they were supposed to have let go of.
The first thing I did was to put a trace() in my deconstructor to make sure it was being called, yes it was. WTF? After some more digging, I then saw that this particular DisplayObject was flagged to not attach itself to the event dispatcher in the first place. (Wait, you mean that addEventListener hadn’t even been called in the first place? Yes!) So I switched the flag so that the DisplayObject would attach to the event dispatching model and guess what, this time it got GC’d after the deconstructor call.
So why is removeEventListener causing this to happen, the API docs define the method as:
“Removes a listener from the EventDispatcher object. If there is no matching listener registered with the EventDispatcher object, a call to this method has no effect.”
Has no effect, huh? But it seems to be doing something. Has anyone noticed anything similar to this?
Comments(5)


