AS3: Weak Listener References Not Appropriate During Initialization?

Posted by TheDarkIn1978 on Stack Overflow See other posts from Stack Overflow or by TheDarkIn1978
Published on 2010-04-19T07:11:40Z Indexed on 2010/04/19 7:13 UTC
Read the original article Hit count: 362

as i currently understand, if an event listener is added to an object with useWeakReference set to true, then it is eligible for garbage collection and will be removed if and when the garbage collection does a sweep.

public function myCustomSpriteClass() //constructor
    {
    this.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownListener, false, 0, true);
    this.addEventListener(MouseEvent.MOUSE_UP, mouseUpListener, false, 0, true);
    }

in this case, is it not appropriate to initialize an object with weak references event listeners, incase the garbage collector does activate a sweep removing the objects event listeners since they were added during initialization of the object?

in this case, would it only be appropriate to create a type of deallocate() method which removes the event listeners before the object is nullified?

© Stack Overflow or respective owner

Related posts about actionscript-3

Related posts about garbage-collection