Help with profile

Use this forum for questions on how to use .NET Memory Profiler and how to analyse memory usage.
Post Reply
Posts: 7
Joined: Mon Dec 07, 2009 7:34 pm

Help with profile

Post by » Mon Dec 07, 2009 7:41 pm

I have a project that has two forms. Form1 is the main form and Form2 is a child of Form1. The only control that I have is a button on Form1 that opens Form2. After I close Form2 I take a snapshot of memory and there a some results that I don't understand. They both reference the namespace Microsoft.Win32.SafeHandles. One is SafeTokenHandles and the other is SafePEFileHandle. The Profiler states the both have been Garbage Collected without being properly Disposed? Is this something I need to worry about? If so, how do I find what needs to be disposed?
T Kelley

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

Post by Andreas Suurkuusk » Tue Dec 08, 2009 3:53 pm

SafeTokenHandles and SafePEFileHandles are sometimes created by the framework itself, and they are not always properly disposed. There's not much that you can do about these undisposed instances, and often you can hide the warnings about them by selecting "View->Ignore framework issues".

In another forum post I replied to a similar question:
An undisposed instance indicates that an instance has been collected (or at least finalized) without being properly disposed. Since the instance have been collected (and the finalizers have run), having undisposed instances do not indicate a memory or resource leak. It does however indicate that the memory or resource utilization might not be optimal (e.g. by delaying the release of a resource and causing finalization of instances).

If possible, you should try to make sure that all instances are correctly disposed. However, it's pretty common that the .NET Framework itself causes undisposed instances and there's nothing you can do about it.

The SafePEFileHandle is a wrapper class for an unmanaged resource. Failing to dispose instances of this class will keep the resource alive for an unneccessarily long time, but the finalizer will make sure that the resource is eventually released.
Best regards,

Andreas Suurkuusk
SciTech Software AB

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 10 guests