Add SPDisposeCheck to Visual Studio External Tools

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

SPDisposeCheck as VS External Tool

Here’s some output from the included example solution:

SPDisposeCheck Output in VS

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 SPSite or 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.


3 Responses to “Add SPDisposeCheck to Visual Studio External Tools”

  1. Links (2/15/2009) « Steve Pietrek - Everything SharePoint Says:

    […] Add SPDisposeCheck to VS External Tools […]

  2. Todd Bleeker Says:


    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.

  3. Robin Says:

    Hi Keith (and Todd ;),

    thanks for this easy but oh-so-handy tip :)


Comments are closed.

%d bloggers like this: