Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Identify IDisposable objects

i have to review a code made by some other person that has some memory leaks. Right now i'm searching the disposable objects to enclause them with the using statement and i would like to know if there is a quick way that tells you all the disposable objects declared in. I mean something like resharper or another visual studio plugin.

thanks.

like image 518
David Espart Avatar asked Feb 26 '09 15:02

David Espart


2 Answers

I know what you mean. I don't know, but look at FxCop. It might have a rule in there somewhere that checks whether objects implementing IDisposable are not disposed. Just a hunch, mind.

UPDATE: Mitch Wheat writes:

FxCop includes the rule, thats says all types that derive from types that implement IDisposable should implement the Dispose() pattern

Thanks, Mitch.

like image 69
Neil Barnwell Avatar answered Sep 28 '22 04:09

Neil Barnwell


You could do this with ReSharper. With ReSharper you can navigate implementations of any interface with ease by using Alt-End, but for a popular interface such as IDisposable this is not practical.

Here's what you could do:

  1. Go to Object Browser (Ctrl-Alt-J or View->Object Browser)
  2. Find System.IDisposable
  3. Right click and select "Find Usages Advanced" (ReSharper's menu item)
  4. User Find, check "Implementations", under Scope choose Solution
  5. You will get a list of all types (of your solution) implementing IDisposable. Those in bold are the ones you want - they implement IDisposable directly.

Hope that helps.

like image 37
Igal Tabachnik Avatar answered Sep 28 '22 04:09

Igal Tabachnik