Flex ArrayCollection: RemoveAll() vs new ArrayCollection
When would you want to use removeAll() vs开发者_如何学编程 just new ArrayCollection when you want to clear an array collection.
Remove all iterates though each item in the list. I can't see a case when I would want to use it.
You'd probably want to use removeAll in the case where the ArrayCollection contains items with a propertyChange event dispatcher attached to them (with bindings?). The removeAll will clean these events nicely for you.
However, if you use new ArrayCollection the old ArrayCollection will be deallocated from the reference, but may never be garbage collected, because it still has references attached. This could potentially lead to memory leaks.
Note that removeAll() will not in fact remove ALL elements from collection in case a filterFunction is defined and applied (.refresh()) and there are any elements in source Array, rejected by this filter.
精彩评论