How to clear an unused Array from Memory ?

let say i have this code:

private var myArr = new Array();

myArr.push("blah");
myArr.push("bleh");
myArr.push("bloh");
myArr.push("bolb");
.
...and 500 more members here
.
myArr.push("zzzz");

print(myArr);

my question:

1.) Once i don’t need that myArr how am i supposed to clear it from the memory so it won’t leave any garbage ?
Does this enough to clear it from the memory (because there is no Destroy function for array):

myArr.Clear();
myArr = null;

2.) What’s happen in the memory when i overwrite that myArr with another array ?

private var myArr = new Array();
private var oneMemberArr = new Array();

myArr.push("blah");
myArr.push("bleh");
myArr.push("bloh");
myArr.push("bolb");
.
...and 500 more members here
.
myArr.push("zzzz");
print(myArr);

oneMemberArr.push("only one member");
myArr = oneMemberArr;

what’s happen with all those 500+ members above,
does it leave hanging in the memory (as a garbage) ??

I would love to here some thoughts on memory leaks from more knowledgeable people. I am guessing some forum searching will shed some light though.

I am guessing that most everything has a sort of Scope(is that the right word?) mechanism to it. ie if nothing is referencing a particular Vector3 array, it’s destroyed automatically.

I would bet that Unity tries to do everything it can to handle memory leaks “under the hood.” For one, none of the tutorials mention anything on memory leaks. Anecdotally, I’ve run simulations on my old computer for several days without any complications.

One thing that I have read that can “leak” is textures. Something about needing to eventually Destroy() textures created with “new Texture()”.

Any thoughts from the old hands?

If the garbage collection system won’t dispose of an array you set to null then it’s a fairly serious bug (i.e. the garbage collection system is no use at all).

I gather that Unity-specific stuff has to be handled by you. Textures, as mentioned: if you’re creating them then you should destroy them. Materials as well, especially since Unity creates materials for you behind the scenes if you alter them. (i.e., you have two objects with the same material on them, then you change the color of object A, now you have another material which will stay around in your scene even if you destroy the objects. If you’re doing a lot of individual texture animating, it’s advantageous to instantiate the materials yourself instead of letting Unity do it, so you can destroy them when you’re not using them. Otherwise they don’t get removed until you load another scene…at least I hope that removes them.)

All the generic stuff should be handled by the garbage collector though.

–Eric