Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

As3 - How to clear an array efficiently?

Tags:

I've been looking to clear an array in ActionScript 3.

Some method suggest : array = []; (Memory leak?)

Other would say : array.splice(0);

If you have any other, please share. Which one is the more efficient?

Thank you.

like image 452
ALOToverflow Avatar asked Feb 10 '10 14:02

ALOToverflow


2 Answers

array.length = 0 or array.splice() seems to work best for overall performance.

array.splice(0); will perform faster than array.splice(array.length - 1, 1);

like image 168
Jason Avatar answered Sep 22 '22 12:09

Jason


For array with 100 elements (benchmarks in ms, the lower the less time needed):

// best performance (benchmark: 1157)
array.length = 0;
// lower performance (benchmark: 1554)
array = [];
// even lower performance (benchmark: 3592)
array.splice(0);
like image 43
n4pgamer Avatar answered Sep 24 '22 12:09

n4pgamer