Page 1 of 1

Why trigger a SnapShot will still drop down the memory.

Posted: Thu Sep 22, 2016 2:54 am
by Shawn
Hi,
I have a

Code: Select all

GC.Collect()
at end of my testing program, I understand this is a blocking call and will free all un-reachable objects, if my program have no extra work any more, then the used memory should stayed in a fixed value, and this has been proved via the Graph and statistics.
But at this point, once I performed a SnapShot, I still can see a extra memory(Live managed bytes) drop down , what did the snap shot do here? not just trigger a Full GC?

Re: Why trigger a SnapShot will still drop down the memory.

Posted: Thu Sep 22, 2016 8:52 pm
by Andreas Suurkuusk
When you collect a snapshot in the profiler, the profiler performs a sequence similar to:

GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();

It may even repeat this if it believes that there are still more instances to finalize.

So in your case, there's a possibility that there are instances with pending finalizers after your call to GC.Collect() and that would explain why the live bytes value decreases when you collect the snapshot.