ShoulO ShoulO - 1 year ago 197
C# Question

clearing memory after arrays are used in unity

I want to clear memory from "spent" arrays of vectors or integers. Arrays themselves and values inside are no longer necessary.
I am simply doing:

System.Array.Clear(SomeArray,0,SomeArray.Length );

Does this clear the memory and it becomes available for other uses?
Or does GC still have to do it? (if so how to do it without leaving any to GC )

P.S. I figured that iterating through and nulling each value is pointless since you can't null vector or int.


Answer Source

This method only clears the values of the elements; it does not delete the elements themselves.

Look into below documentation:

By setting NULL is not an indication to GC to collect it. Probably you can call GC.Collect(). refer for more information.

Also keep in mind "GC.Collect" call is a overhead.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download