1 Reply Latest reply on Jan 25, 2007 9:09 AM by ur_dtrain

    addEventListener and GC

    tlc
      i have a class which extends Sprite

      quote:

      public class myObj extends Sprite {
      function myObj() {
      this.addEventListener(Event.ADDED, this.onAdded);
      }
      private function onAdded(e:Event):void {
      this.addEventListener(Event.REMOVED, this.onRemoved);
      }
      private function onRemoves(e:Event):void {
      this.addEventListener(Event.REMOVED, this.onRemoved);
      }
      }


      i leave the Event.ADDED even it have removed from the DisplayList, because i might use it again later.
      my question is, if i have no reference to this instance, will the GC collect it? (because there still have one listener not yet unregister)

      thank you
        • 1. Re: addEventListener and GC
          ur_dtrain Level 1
          I'm not sure about the garbage collection, but you can always store a reference to the object at the time of removal. Functions like RemoveChild and RemoveChildAt, both return a reference to the removed component, which you can store for later use:

          var removedObject:Object;
          removedObject = someDisplayObject.removeChildAt(0);