Why trigger a SnapShot will still drop down the memory.

Use this forum for questions on how to use .NET Memory Profiler and how to analyse memory usage.
Post Reply
Shawn
Posts: 5
Joined: Thu Nov 14, 2013 7:38 am

Why trigger a SnapShot will still drop down the memory.

Post by Shawn » Thu Sep 22, 2016 2:54 am

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?

Andreas Suurkuusk
Posts: 1000
Joined: Wed Mar 02, 2005 7:53 pm

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

Post by Andreas Suurkuusk » Thu Sep 22, 2016 8:52 pm

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.
Best regards,

Andreas Suurkuusk
SciTech Software AB

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 3 guests