Alex Rivera | Logout

Can Visual Studio warn me when I forget to dispose an IDisposable object?

Asked 2009-07-06T19:04:59.663
15

Can Visual Studio 2008 be configured to give me a warning when I forget to dispose an object that implements IDisposable?

Edit
Report

1 Answer

1

I don't think it can be done at compile time.

however, it can be done at runtime.
I have created an abstract class 'Disposable' (which implements IDisposable, and implements the Disposable pattern). In the finalizer, I issue an Assert when the finalizer is called, and the object has not been disposed.

I've based this on an article of Ian Griffiths:

http://www.interact-sw.co.uk/iangblog/2004/04/26/yetmoretimedlocking

answered 2009-07-06T19:09:16.037

Your Answer