Best way to remove all elements from an ActionScript Array?

I'd say:

myArray = [ ];

That's explicit, short, and makes good use of the VM's garbage collector.

Your first alternative runs a lot of interpreted code to get the same result.

I don't know that the second does what you want; if it does, it's hacky, unclear.

The "new Array()" variant of the third alternative is just wordy, offering no advantage over an array literal. If you also write JS and use JSLint, you'll get yelled at for not using the array literal form.


I'm afraid to say but Warren Young is wrong when he said that setting the myArray = [] cause the garbage collector to pick up the array.

as you have the ability to add a reference to itself within itself, and therefore would never be collected and using up memory, especially if the array has some Sprites in the array, as they too would have the array references them and they too would never be collected.

Sly_cardinal and Richard Szalay are 100% correct. but the length parameter is not needed in Richard's.

To totally clear the array and make sure its collected by garbage then

myArray.splice(0);
myArray = null;