You wrote:
I have declared an array in C# this way:
public ushort[][] pixels16;
To be clear: You have NOT declared an array.
You have declared a reference, called pixels16
.
That reference may be to any 2-D array of ushorts
, but it initially references nothing (null).
You actually create the array when you do:
pixels16 = new ushort[500, 500];
Similarly, you can make that array eligible for garbage collection when you no longer reference it:
pixels16 = null; // Now the array is ready for Garbage Collection.
The garbage collector is very good at its job, and it is not recommended that you manually call for garbage collection. It will, in all likelyhood, collect the garbage very quickly and efficiently, and keep your program running with no problems.