Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find not disposed IDisposables

I am looking for memory leaks in a huge code base so going line by line and observing for every possible location of where an IDisposable is used without being put in a using statement or without being disposed is not an option.

I am currently using NDepend with the query from this answer NDepend CQL Query for missing IDisposable implementation but that is not what I need. I need to know if an object is instantiated and later on not being disposed of. How to write a query in NDepend that will find those objects? Or if that is not possible then how to get a list of places where IDisposable objects are being instantiated?

like image 842
Mihail Shishkov Avatar asked Mar 05 '15 15:03

Mihail Shishkov


People also ask

How do you find Undisposed objects in C#?

The simplest way to find undisposed objects is to add some logging to the finalizer of each disposable type. Running the application through typical scenarios and checking the logs should tell you which types are not being disposed.

What happens if Dispose is not called?

Implement a finalizer to free resources when Dispose is not called. By default, the garbage collector automatically calls an object's finalizer before reclaiming its memory.


1 Answers

Take a look at this: CA2000: Dispose objects before losing scope

like image 116
milen.vichev Avatar answered Oct 21 '22 14:10

milen.vichev