I am trying to figure out what exactly increases the memory consumption with each iteration:
ManagementObjectSearcher Win32_Process = new ManagementObjectSearcher("Select * From Win32_Process");
while (true)
{
foreach (ManagementObject PS in Win32_Process.Get()) { }
//Not using the garbage collector GC.Collect()
Thread.Sleep(1000);
}
Look at graph of used memory:
I was convinced that the auto garbage collector cleared memory after cycles. Why is this not happening? How to avoid memory expansion without using GC.Collect()
? Thanks