Say you call:
void Foo(){
int[] a = new int[5];
}
In C# there is no way to undefine the variable a
. That means a
will be defined in Foo
even if you set a
to null.
However, at the end of Foo
a
will fall out of scope. That means no code can reference it, and the garbage collector will take care of freeing the memory for you the next time it runs, which might not be for a long time.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…