When u register an EventListener to en IEventDispatcher instance not using weak references, the object won't be garbage collected untill all references got null. This not only affects references by objects and arrays, but also eventlistener. Using weak references will allow the garbage collection to remove objects, even if there are eventlisteners left.
But using weak references will also slow the machine down, if i remember right aboit 10clock cycles. Here's a blog entry u might want to read: http://www.onflex.org/ted/2008/09/useweakreferencesboolean-false.php I was using weak refernces heavily, but u don't have to. When u are using eventlistener as members of the instance, they don't have to be weak, since the whole object can be garbage collected. But, when u have for example a sprite instanciated in the scope of another object, u should for example use the eventlistener for Event.ADDED weak referenced. The other listeners will be added and removed depending on the state of sprite -> an example; why should a sprite listen to mouse events, when it is not in the displaylist. Add the necessary listeners when it is on the stage. So it always depends on what u are doing. Best regards. --- In flexcoders@yahoogroups.com, "iliev_niki" <[EMAIL PROTECTED]> wrote: > > I have a question on the weak references when adding a listener like > this: > > btnSave.addEventListener(MouseEvent.CLICK, onBtnSaveClick, false, 0, > true); > > I have found this approach with weak reference as an advise > somewhere, but I would like to understand what happens really. > > If we add a listener specifying useWeakReference = true as in the > example above, does this mean that the garbage collection might > remove unexpectedly the event listener and the mouse event handling > to stop working? > > When using weak reference for the event listener, is it needed to > explicitly remove the event listener at some point in time? > > In general what is the best practice in this regard? > > Kind Regards, > Nikolay >