AS3 / Flex Performance - new ArrayList and ArrayList.removeAll ()

Which is actually faster? Just create a new ArrayList / ArrayCollection or reuse the existing one and remove its elements?

I am developing for mobile phones where performance is always an issue, so I use the fastest method.

+3


source to share


2 answers


even faster mycollection.source = [];

(unlike mycollection.source = new Array()

)

Another option is to use linked lists and object pools. Object pools allow objects to overwrite their properties instead of deleting the object and creating a new one. If you then store them in a linked list rather than an array, looping through them is much faster. So if you just want to go through a bunch of objects go with linked lists, but if you need to do any sorting then array and vectors will be faster.



Another problem is memory usage. not just for storing applications with less memory, but the more objects you declare, the more work the garbage collector has to do when it comes time to clean up.

+5


source


Here's an interesting blog post about optimizing ArrayList / ArrayCollection cleanup. The setup appears to be mycollection.source = new Array()

significantly faster than mycollection.removeAll()

with large datasets, as removeAll ensures that all event listeners are removed.



As is the case, it is likely that the new ArrayList will beat ArrayList.removeAll (), but the new original array may be a better option as it should have less impact on bindings / listeners.

+5


source







All Articles