views:

92

answers:

4

c# question - is there a tool to identify where I should/can use a "using" statement to ensure resources are closed? (to avoid memory leaks etc)

Including both the cases that:

a) there are resources not been closed and

b) syntax is using a try-catch-finally and identies this could be changed to a using

Thanks

+2  A: 

I'm not sure if it covers case b explicitly, but Gendarme is a fine tool that will tell you when you don't have a using statement around disposable objects.

Mark Rushakoff
oh - can you use it on a non-mono project then? i.e. VS2008 c# 3.5
Greg
@Greg - yup, Gendarme has worked great for me with .net 2.0 and 3.5 projects
mjd79
@Greg: On Windows, Gendarme works nicely as a standalone tool, analyzing compiled .NET assemblies. The standalone tool is at http://www.ohloh.net/projects/gendarme/download?package=Win32+installer
Mark Rushakoff
+1  A: 

Don't know if this is the kind of tool that you're looking for, but Code Rush will highlight your code when you have an object from a class that implements IDisposable and you're not diposing it.

Fernando
I've got ReSharper at the moment - I don't think it has the support yet :(
Greg
I think ReSharper is way better than CodeRush. Anyway, why don't you give CodeRush Express a try? Maybe the express version can do what you want... http://www.devexpress.com/Products/Visual_Studio_Add-in/CodeRushX/
Fernando
+1  A: 

Take a look if you can to enable code analysis in your project and turn on Microsoft.Reliability: Dispose objects before losing scope rule

Rubens Farias
seems to require Team System?
Greg
sorry Greg, I can't to confirm right now, as I just have Team System here =/
Rubens Farias
Isn't FxCop able to perform this kind of code analysis ?
Laurent Etiemble
A: 

FxCop is a free tool from Microsoft that can do this. It's also included in the "Team System" variants of Visual Studio 2005+

Joe