Hi Dale, I just read the entire conversation, and i have a better simpler solution. Instead of binding the arrayCollectiopn in your modelLocator, bind the getter.
[Bindable(event="entriesChanged")] public function get prodList() : ArrayCollection { return _prodList; } After that in each of your functions that removes/adds elements from/to the _prodList, just fire the event. dispatchEvent(new Event("entriesChanged")); Hope it helps, Regards, Josef --- In flexcoders@yahoogroups.com, "dbronk" <[EMAIL PROTECTED]> wrote: > > > Probably the easiest thing to do would be to make the listener > reference > > weak. Or, create an accessor function for the arraycollection and > remove > > the listener from the old arraycollection and add a listener to the new > > arraycollection if they are not the same object. > > Will you expand on this please? I did the following code hoping to > solve the issue, but I'm very worried this goes much deeper than just > ArrayCollections and goes to every object that has an event listener > on it. If that is the case I can't see how leaks can be stopped. > > snippet (remember entire class is bindable) > > private var _prodList : ArrayCollection = new ArrayCollection(); > > public function get prodList() : ArrayCollection > { > return _prodList; > } > > public function set prodList(list:ArrayCollection) : void > { > _prodList.removeAll(); > > // This line doesn't work as it adds a single element of type > ArrayCollection > _prodList.addItem(data); > > // This line doesn't work as it adds a single element of type Array > _prodList.addItem(data.toArray()); > > // So, tell me without having to loop through the data > ArrayCollection, how do I get the elements from one AC to another? > } > > > I hope that I am simply not seeing something very simple or am simply > missing a basic pattern, but I see this as a very, very big deal as > when I need to set a new list, I should not have to know that other > people have set listeners and know to remove them. > > Thanks, > Dale > > > --- In flexcoders@yahoogroups.com, shaun <shaun@> wrote: > > > > Hi, > > > > ben.clinkinbeard wrote: > > > Glad you got it working. Yea, its unfortunate (but unavoidable) that > > > reinitializing a var kills the listeners. (Actually, I think > > > reassigning like that could cause a memory leak, can someone confirm?) > > > If its feasible you may want to replace those lines with > > > prodList.removeAll() and then you should be able to get rid of > <Binding>. > > > > > > Ben > > > > > "dbronk" <dbronk@> wrote: > > >>Second, swapping my mx:Binding with adding a listener on > > >>CollectionEvent.COLLECTION_CHANGE definitely did the trick, but with > > >>one bad consequence. If somewhere along the way code was written > > >>prodList = new ArrayCollection, it broke. My solution to that was to > > >>add back the mx:Binding, but when that fires, it simply runs a > > >>function that reestablishes the event listener on > > >>CollectionEvent.COLLECTION_CHANGE. Now it seems to work no matter how > > >>I set the list. > > > > I would have thought the old array collection would have been garbage > > collected because the arraycollection itself would no longer have any > > references to it. It would reference the handler function and the > > handler fucntion would reference the object it was declared in, but > > the array collection itself would be unreachable AFAIK. > > > > However, reading the docs for EventDispatcher it seems as though > > creating a new ArrayCollection could result in a memory leak. > > > > --- > > /langref/flash/events/EventDispatcher.html#addEventListener() > > > > If you no longer need an event listener, remove it by calling > > removeEventListener(), or memory problems could result. Objects with > > registered event listeners are not automatically removed from memory > > because the garbage collector does not remove objects that still have > > references. > > --- > > > > Probably the easiest thing to do would be to make the listener > reference > > weak. Or, create an accessor function for the arraycollection and > remove > > the listener from the old arraycollection and add a listener to the new > > arraycollection if they are not the same object. > > > > cheers, > > - shaun > > >