Indeed, I used the size of a personal mem, because the one that is closest to one in Process Explorer
if I rewrite the program using GC.GetTotalMemory as follows:
using System; namespace GCMemTest { class Program { static void Main(string[] args) { System.GC.Collect(); long startBytes = System.GC.GetTotalMemory(true); { string[] strings = new string[2000000]; for (int i = 0; i < 2000000; i++) { strings[i] = "blabla" + i; } strings = null; } System.GC.Collect(); long endBytes = System.GC.GetTotalMemory(true); double kbStart = (double)(startBytes) / 1024.0; double kbEnd = (double)(endBytes) / 1024.0; System.Console.WriteLine("Leaked " + (kbEnd - kbStart) + "KB."); System.Console.ReadKey(); } } }
Then output:
Leak 0K.
Only when I have "stringings = null;" this is so, delete it and I will skip 100 MB. This means that the local area in the main procedure does not free the array. If I translate this part into the static Test method and call it instead, I will skip a few bytes. I suggest that I should learn from this that local regions are ignored by the GC.
ava
source share