1 Reply Latest reply on Aug 12, 2009 6:57 PM by Flex harUI

    weak listening

    phil1943

      I have an object with about 6 different event listeners attached to it.

      Normally when I delete that object I would add code to remove those 6 listeners so it could be garbage collected.

      To save me typing out all the removeEventListener code can I simply add weak references in the beginning ?

      Is there any disadvantage in doing this ?

       

      Thanks for any advice.

        • 1. Re: weak listening
          Flex harUI Adobe Employee

          You may not even need to do that.

           

          If there is an object A and B and C are listening to it:

           

          A.addEventListener("foo", B.fooHandler);

          A.addEventListener("foo", C.fooHandler);

           

          There are no references from B or C to A so those listeners don't have to be removed.  It turns out that A has references to B and C's fooHandler, not the other way around.

           

          You can use weak reference listeners, but they have slightly higher overhead and don't get gc'd as often, and can cause intermittent errors if they don't get gc'd when you want them to.

           

          Alex Harui

          Flex SDK Developer

          Adobe Systems Inc.

          Blog: http://blogs.adobe.com/aharui