How can I remove a vector or array in AS3?

What is the most efficient way to remove an array or vector in ActionScript 3?

I always just reinitialized them:

vector = new Vector.<T>(); array = []; 

It doesn't look like there is an empty() function or something like that.

Is there a better way?

+6
source share
2 answers

Reinitializing the array in most cases is fine, as the garbage collector simply sweeps the old array. However, if you want to clear the array without creating a new one, you can set array.length = 0

+13
source

Another option is to use the splicing method.

Array :: splicing documentation

For an array, the following call empties it:

 array.splice(0); 

The second parameter is applied to the vector, so the call becomes:

 vector.splice(0, vector.length); 
+6
source

Source: https://habr.com/ru/post/908676/


All Articles