views:

96

answers:

2

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.

+2  A: 

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);

Jason W
+1  A: 

I wonder, why you want to clear the Array in that manner? clearing all references to that very array will make it available for garbage collection. array = [] will do so, if array is the only reference to the array. if it isn't then you maybe shouldn't be emtpying it (?)

also, please note that`Arrays accept Strings as keys. both splice and lenght operate solely on integer keys, so they will have no effect on String keys.

btw.: array.splice(array.length - 1, 1); is equivalent to array.pop();

greetz

back2dos

back2dos
I do want to make it avaible to garbage collection, I want to empty it.
Frank
Pretty sure arrays in AS3 don't accept strings as keys. Objects do, but not Arrays.
Austin Fitzpatrick
@Omnomlets: you're wrong. next time, try verifying your statements.
back2dos
@back2dos -- You're right. I suppose that's because Array extends Object in the first place. Thanks! You learn something every day.
Austin Fitzpatrick