1 Reply Latest reply on Jul 27, 2012 8:46 AM by Flex harUI

    do you need to remove an eventlistener added in mxml

    NilsTT Level 1

      First of all to avoid confusion: the documentation is quite clear: you can't remove such an eventlistener.

       

      Than why this question

       

      Say you declare a button in mxml, typically you assign the click event listener as wel in mxml.

       

      But if the button is removed from its parent view, the question is whether the event listerer (and thus the button object as well) will be garbage collected or not.

       

      An object will be garbage collected if there are no more pointers, or only pointers using weak reference pointing to it.

       

      So the question is: does assigning and eventlistener in mxml sets the "useWeakReference" parameter to true. (or am I missing something here).

       

      If yes => OK

      If no => Big problems, check all your code for mxml assigned eventlisteners and replace them by an addEventListener and corresponding removeEventListeners.

        • 1. Re: do you need to remove an eventlistener added in mxml
          Flex harUI Adobe Employee

          A listener sets up a reference from the dispatcher to the listener, not the other way around.  It is rare to need to remove the event handlers in MXML.

           

          That said, MXML tags can’t be easily removed from memory either because the generated code for the MXML might have other references to the object.  In general, if you want to get rid of it, don’t create it in MXML or use states/includeIn/excludeFrom.