Best way to properly to clear/ null/ an Array

Hello As3 community,

I know this is a question already answered a couple of time on various forum, but still,
I have a lil doubt in AS3 as there is several answers…

So finally what’s the best way to clear/empty the content of an array of numbers and make it ready for garbage collection?
And second doubt : Is there a different way to do so for an array of object or sprites?

By best way I mean, the fastest ( time to process it) but still clean enough to ensure it will not stay something which could delay or block the garbage collection to be done as soon as possible.

So far I used the way below:

1-
array= [];
array=null;

2-
array.length = 0;
array=null;

3-
array.splice(0);
array=null;

I probably miss other ways, so feel free to complete it.

According to the doc
https://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Array.html#length

Note: If you assign a value to the length property that is shorter than the existing length, the array will be truncated.

and this article
Clearing an Array or Vector

it should be

array.length = 0;

now, for Array in any case it does not really matters as it would be in most case be garbage collected, unless very special cases

but for Vector yep you could get memory leaks if not paying attention

In general, I would say do not even bother.

Now in “production mode” where you want to measure stuff and keep an option later to optimize because you really do manipulate a lot of data etc.

ideally you want to fire Scout CC and deep dive into it
or use flash.sampler.getSize()

see also

1 Like

Awesome! Thank you for this complete answer Zwetan!