I recently debugged some code that was a bit lost. This is a long program that runs as a Windows service.
If you find a class that has an interface IDisposable
, it tells you that some of the resources it uses are outside the scope of the garbage collector to clean you up.
The reason you say this is because you, the user of this object, are now responsible for clearing these resources. Congratulations!
As a conscientious developer, you are pushing for a method call .Dispose()
when you are done with an object to free these unmanaged resources.
There is a good template using()
that will help clear these resources after they are completed. Which only leaves detection of which objects cause leakage?
To help keep track of these unmanaged rogue resources, is there any way to query which objects loitering around waiting to be Disposed at any given time?
source
share