If you are the parent, adding an event listener to a child does not create a reference to the child, it creates a reference from the child to the parent, so it won't affect collection of the child when you release all other references to that child.
________________________________ From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of flexaustin Sent: Thursday, August 07, 2008 2:05 PM To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: Garbage Collection and event listeners But it does matter. Say I create an object on stage through code. var result:Boolean = super.handleAdd(event); var child:UIComponent = event.relatedObject as UIComponent; child.addEventListener(MouseEvent.CLICK, handleChildClick, false, 0, true); then later I delete all the child objects there will be a reference from the addEventListener floating around so child won't be removed from memory. When you say a to b what do you mean? --- In flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> , "Alex Harui" <[EMAIL PROTECTED]> wrote: > > No one call can remove all listeners. No one call can remove all > references, just one at a time. > > If you add a listener on yourself, there is no need to remove it. It > might slightly help if it is a DRC object, but eventually it will be > garbage collected. > > a.addEventListener("foo", b.someMethod) creates a reference from a to b, > not the other way around. > > ________________________________ > > From: flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> [mailto:flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> ] On > Behalf Of flexaustin > Sent: Thursday, August 07, 2008 10:27 AM > To: flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> > Subject: [flexcoders] Garbage Collection and event listeners > > > > Is possible to remove all event listeners by doing something like the > following? > > mc.removeEventListener(*,*,false); > > Though not sure how you would get the count of eventlisteners or > iterate through them? > > And as far as deleteing any reference to an object can you override > removechildren and add > for(var i:int=0; i<this.numChildren-1; i++) > { var chld:DisplayObject = this.getChildAt(i); > chld.deleteReferenceOnParentDocument(this.parent); > } > > Or is there a best practice when for when you write code like this: > addEventListener(ChildEvent.CHILD_ADDED, > handleAdd); > > To override the removeChilden function to remove the event listener > above? > > Thanks in advance. > > --JDog >