Is cleaning a multidimensional array with reference, easy?

Hi!

I use some multidimensional arrays / objects::
var arr = [];
arr[0] = [];
arr[0][0] = "reference to another object"...

If I do this, it is ok?
arr[0] = [];

Or I have to clear child one by one (recursive)?
arr[0][0] = null;
arr[0] = [];

Thanks a lot.

why don’t you simply try it and see for yourself?

the thing is you ask “what is best” but you don’t say for what purpose
are you after performance/speed? are you about not having memory leak?
maybe it is about doing deep copy of arrays with/without the references?
it is about deleting specific elements of an array or all elements?
something else?

check those docs

use those tools

read a bit about

but no matter what, test for yourself depending on what you’re trying to do

getSize() will help you to see the size of an object, for ex: an array size before and after you delete some elements

JSON.stringify() can be used as a quick dump of the content of an object

you can delete elements in an array in few different ways

  • set the Array length to zero, eg. array.length = 0
  • assign/overwrite an empty array, eg. array = []
  • use the splice() method, eg. array.splice(0)

AS3 Garbage Collector has been improved dramatically, so it should intercept any object without a reference to he application even if cross-referenced, but it is always better to cleanup properly.
The methods you described are ok to clear the array itself, but whatever is referenced by the array might require to be prepared for being properly garbage collected.