Monday, 14 July 2008

Using IDisposable - don't feel guilty about 'hijacking' it!

Jason Bock links to my post on (Mis)Using IDisposable (with some kind words about the "cool content" on the rest of blog - thanks Jason!), and says that he sometimes feels "a little guilty about using IDisposable for something other than managing unmanaged resources". I guess the title of my post did suggest that I was encouraging others to indulge along with me in some slightly naughty behaviour.

But nothing so underhand is going on. Eric Gunnerson, previously on the C# design team, has said 

we decided to name it “using” rather than something more specific to disposing objects so that it could be used for exactly this scenario.

So, Jason, we all have the highest authority to (mis)use using and IDisposable for purposes beyond resource clean-up.


Jason Bock said...

Very nice :)

I get Eric's point, because at the end of the day "using" is just a code generating pattern. It's unfortunate that most if not all the docs are concerned about it being just for unmanaged resource because it can come in very handy for other scenarios.

Post a Comment