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.
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);
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With