Skip to main content
Inspiring
July 15, 2014
Answered

AS3 Best way to clear an array

  • July 15, 2014
  • 1 reply
  • 1534 views

What is the best way to clear an array? (performance and resources)

array.length = 0;

array = [];

array.splice(0);


This topic has been closed for replies.
Correct answer kglad

array.length=0;

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
July 15, 2014

array.length=0;

gibsyAuthor
Inspiring
July 16, 2014

If i use something like this:

arr = new Array();

some code

.

.

.

arr = new Array()

The variable arr won't be replaced faster in the memory with this new one?

kglad
Community Expert
Community Expert
July 16, 2014

that's creating a new array which is extra work, and it's adding an array to the objects that flash will gc, and that's extra work.

assigning the length to 0 is the most efficient way to clear an array.