views:

96

answers:

3

Is there a way to automatically check existing C# source code for instances of objects that are not properly disposed of ie. using try / catch / finally or using statements? Or do I need to just manually look at the code?

+3  A: 

Take a look at FxCop for VS2010 - I believe they restored the DisposeObjectsBeforeLeavingScope rule - which may do exactly what you want.

LBushkin
I downloaded the Trial version of VS2010 Premium and it does indeed have this rule CA2000. Thanks.
TooFat
A: 

HTH

Sunny
A: 

CodeRush has some support for spotting obvious variants of this. Another possible option is (perhaps via an optional compilation symbol) add a finalizer to your own IDisposable objects, and complain loudly if they get finalized without being disposed (set a bool flag in the Dispose). But note: having a finalizer changes the behaviour of the objects, so don't leave it in production code (or even your regular unit tests).

Marc Gravell