Garbage Collection

Use this forum for questions on how to use .NET Memory Profiler and how to analyse memory usage.
Post Reply
cgreeno
Posts: 1
Joined: Fri Oct 20, 2006 8:44 am

Garbage Collection

Post by cgreeno » Fri Oct 20, 2006 9:17 am

We have a very large app that has a few known memory leaks. We are attempting to track down the leaks now. We have been using your “Real Time” feature to assess the problem. Our process, thus far, has been to open the form with the leak then close it. After the close we call the GC.Collect to explicitly call all 3 levels of garbage collection. Do you think this is the best way to evaluate the app?
When a snapshot is taken is all 3 levels of garbage collection evoked?
When a snapshot is being compared what you would expect to see if all object being disposed properly?

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

Post by Andreas Suurkuusk » Fri Oct 20, 2006 4:18 pm

In order to try to locate a memory leak related to a form, it is a good idea to collect a snapshot before the form is shown and after the form has been closed.
When comparing the snapshots, all classes should ideally have a delta count of zero. However, depending on your application, it is possible that you might have some new instances of some classes without having a "memory leak". The instances can for instance be short-lived instances that are still referenced from local variables or method arguments.

When a snapshot is collected, the profiler tries to make sure that all instances are collected by performing actions similar to:

Code: Select all

GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
So there's no need to call GC.Collect() in your own code to find memory leaks using the profiler. Actually, except under a few scenarios, you should not need to call GC.Collect() from your code.
Best regards,

Andreas Suurkuusk
SciTech Software AB

Post Reply

Who is online

Users browsing this forum: No registered users and 24 guests