Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Profiler Alarming Statistics

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?

like image 305
l46kok Avatar asked Dec 30 '25 06:12

l46kok


1 Answers

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.

like image 151
Louis Somers Avatar answered Dec 31 '25 22:12

Louis Somers