Reputation: 11790
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.
Upvotes: 14
Views: 4361
Reputation: 15916
Usage Rules CA2213 (DisposableFieldsShouldBeDisposed) and CA2215 (DisposeMethodsShouldCallBaseClassDispose) within FxCop will catch where dispose isn't called correctly in your own classes but i don't believe there is anything out there to check dispose is always called though ironically there is a rule (CA2202) for DoNotDisposeObjectsMultipleTimes
Upvotes: 5
Reputation: 31548
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:
System.IDisposable
IDisposable
. Those in bold are the ones you want - they implement IDisposable
directly.Hope that helps.
Upvotes: 10
Reputation: 391734
Also, depending on whether you use systems like that, if you're using an IoC container, it might go through several layers of code before the service is returned to you through an interface, and it might not be trivial to handle IDisposable in such a case.
Perhaps the interface you resolved doesn't inherit from IDisposable, but the actual service class being used does? How to handle that? etc.
Upvotes: 0
Reputation: 42175
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.
Upvotes: 11