I use dotMemory to profile my application and I noticed the below behavior: inside my code there are some points where I perform garbage collection manually by using
GC.Collect();
GC.WaitForPendingFinalizers();
Inside dotMemory I see that memory is actually freed in these points but if after that I click 'Force GC' even more garabage is collected. What is the way they are doing this and why that memory was not collected by my code and is it possilbe to achieve the same level of collection?
I'm attaching the screenshot where you can see that the gen 2 is almost halved by dotMemory
I've also tried to perform multiple collections i.e.
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
and even though it seems to reclaim a bit more memory it never comes close to how dotMemory performs