3

I've ran a profiler (CLR Profiler 4.0) on my C# application and after the application has been terminated, I was left with the following statistics:

Handles Created: 34,126 Handles Destroyed: 32,844 Handles Surviving: 1,282

I'm under the impression that handles surviving should reach near zero when the program terminates. Am I wrong about this? What are some other indicators that my application is not leaking any memory?

1
  • 1
    "I've ran a profiler (CLR Profiler 4.0)" - Mistake #1. That thing is a broken mess, I don't understand why it is still made available. I would suggest using a better profile to track down performance issues. RedGate has a good .NET memory profiler with a free (full-featured) trial (I'm not affiliated with RedGate in any way). Sep 4, 2012 at 3:19

1 Answer 1

2

Those are the surviving handles just before closing the app. That does not mean your app is leaking memory, all handles, application domains, and other "managed" resources living in the process will be cleaned up. If you have called any native dll's or used other "unsafe" code blocks (unmanaged resources), you have to make sure you release those resources in your code (you can use destructors or the IDisposible interface to do that).

I suggest you start reading from page 44 in "Under the hood of .NET Memory Management" starting from the heading "Generational garbage collection". That should somewhat clear up those results.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.