Garbage Collection in Memory Profiler ?

Use this forum for questions on how to use .NET Memory Profiler and how to analyse memory usage.
Post Reply
abhishabhishek
Posts: 2
Joined: Tue Jun 05, 2018 5:51 am

Garbage Collection in Memory Profiler ?

Post by abhishabhishek » Tue Jun 05, 2018 1:45 pm

Hi ,

Does Memory Profiler execute full garbage collection when we take snapshot in it ?

Thanks,
Abhishek Sharma

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

Re: Garbage Collection in Memory Profiler ?

Post by Andreas Suurkuusk » Tue Jun 05, 2018 2:16 pm

Yes, when you collect a snapshot, the profiler forces the .NET runtime to cleanup as much memory as possible (by performing multiple garbage collections, allowing finalizers to run, and trigger WPF cleanup when profiling a WPF application). This avoids presenting instances that are eligible for garbage collection.

If you wish to see information about unreachable instances or instances in the finalization queue, you can collect the snapshot using the "Collect gen #0 snapshot" command, or by collecting a peak snapshot. A gen #0 snapshot will not perform any heap cleanup, and will include information about unreachable instances. A peak snapshot also includes information about instances collected by the garbage collector.
Best regards,

Andreas Suurkuusk
SciTech Software AB

gianpaolof
Posts: 2
Joined: Wed Jul 25, 2018 2:51 pm

Re: Garbage Collection in Memory Profiler ?

Post by gianpaolof » Wed Jul 25, 2018 3:02 pm

Andreas Suurkuusk wrote:
Tue Jun 05, 2018 2:16 pm
Yes, when you collect a snapshot, the profiler forces the .NET runtime to cleanup as much memory as possible (by performing multiple garbage collections, allowing finalizers to run, and trigger WPF cleanup when profiling a WPF application). This avoids presenting instances that are eligible for garbage collection.

If you wish to see information about unreachable instances or instances in the finalization queue, you can collect the snapshot using the "Collect gen #0 snapshot" command, or by collecting a peak snapshot. A gen #0 snapshot will not perform any heap cleanup, and will include information about unreachable instances. A peak snapshot also includes information about instances collected by the garbage collector.
Hi Andreas,
so the "Collect gen #0 snapshot" command can be used when the wizard for the memory leak tells you to collect the base and the primary snapshot?

thanks
Gianpaolo

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

Re: Garbage Collection in Memory Profiler ?

Post by Andreas Suurkuusk » Thu Jul 26, 2018 3:51 pm

You can use the "Collect gen #0" command when you use the wizard, but I would not recommend it. Since the wizard is used to find memory leaks and help you identify instances that should have been GCed, it makes sense to allow the profiler to clean up as many instances as possible (to avoid false positives). And to clean up as many instances as possible, the normal "Collect snapshot" command should be used.
Best regards,

Andreas Suurkuusk
SciTech Software AB

Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests