In Episode 16 of SharePoint Pod Show, Todd Bleeker had a great SPDisposeCheck tip that bears repeating: add it to your Visual Studio External Tools!
Tools > External Tools > Add
Here’s some output from the included example solution:
My warning against overdependence notwithstanding, this really is a tool that should be run against any object model code.
Of course, Todd had a lot more to say than just this tip, and the whole show is definitely worth a listen. I will disagree on one point though: I wouldn’t consider returning an
SPWeb from a helper method to be a “false positive”. Sure, you can document the behavior, but it’s much easier to maintain over time if these objects are always created and disposed in the same place (if only because you can use
using). I have yet to see an example where this sort of helper pattern couldn’t be refactored out into something more manageable.
February 15, 2009 at 5:27 pm
[…] Add SPDisposeCheck to VS External Tools […]
February 23, 2009 at 2:47 pm
Thanks for posting this tip from the podcast (I’ll refer to it from my blog shortly). I too don’t consider returning an SPSite or SPWeb from a helper method to be a “false positive”. The example I gave was just the only example I could think of that that was simple enough to show how SPDisposeCheck could return an “error” where none exists and still explain it succinctly.
February 24, 2009 at 4:38 am
Hi Keith (and Todd ;),
thanks for this easy but oh-so-handy tip :)