I have 2 snippets with unclear results
This is fine:
List<int> MemoryTest = Enumerable.Repeat(1, 100000).ToList();
Console.WriteLine("RAM: {0:0,0} KB", GC.GetTotalMemory(true) / 1024); //542KB
This is fine aswell (30KB appear to be the overhead from the Console)
List<int> MemoryTest = Enumerable.Repeat(1, 100000).ToList();
MemoryTest = null;
Console.WriteLine("RAM: {0:0,0} KB", GC.GetTotalMemory(true) / 1024); //30KB
Snippet (1) Here I expect not 542KB, because the List<int>
is out of scope
{
List<int> MemoryTest = Enumerable.Repeat(1, 100000).ToList();
}
Console.WriteLine("RAM: {0:0,0} KB", GC.GetTotalMemory(true) / 1024); //542KB
Snippet (2) Even a GC.Collect()
does not help:
{
List<int> MemoryTest = Enumerable.Repeat(1, 100000).ToList();
}
GC.Collect();
Console.WriteLine("RAM: {0:0,0} KB", GC.GetTotalMemory(true) / 1024); //542KB
Why does my GarbageCollector / Managed Code not clear up RAM as expected?