If you’re a SharePoint developer and you haven’t heard about the release of SPDisposeCheck, there are a number of blogs (like the SharePoint Team) you should be reading instead of (or hopefully in addition to) mine. Everyone is understandably enthusiastic—memory management is important and the rules are tricky. However, I’m afraid this is being viewed as something it’s not. To quote Tony Bierman‘s comment on Paul’s post:
I think there should be a “SPDisposeCheck Certified” logo. This badge could be placed on the download pages and in the documentation of both free software and commercial software products as an indication of quality and adherence to best practices.
Let’s be clear: SPDisposeCheck is not definitive. It is a static analysis tool tuned to specific rules documented on the often-cited Patterns By Example. That post has been through perhaps a dozen iterations in the last year, updated as recently as last week. The team has no doubt put a lot of work into it (thanks for that), but there’s no reason to expect the guidance won’t be changed again.
Furthermore, there are countless perfectly safe code patterns, the so-called “false positives”, that will be reported as leaks. The documentation cites SPContext.Web.Site
as an example, and I could probably rattle off a dozen more if pressed to do so. If the developer doesn’t investigate and just “fixes” every warning with using
, more harm is done than good!
The tool will certainly be updated with the latest guidance, and the false positives will be addressed over time, but the core problem still remains: SPDisposeCheck will never know your code as well as you should. I’m sure thousands of leaks will be fixed because of it, and I’m not trying to diminish its value as part of a developer’s toolbox. Just don’t get caught thinking that passing SPDisposeCheck is a substitute for knowing what you’re doing.
That said, a big thanks to Roger, Stefan, Paul and the rest of the SPDisposeCheck team for their efforts to improve their documentation and the quality of our custom code.
January 29, 2009 at 11:15 pm
Thanks for all your help on the SharePoinDevWiki.com with coming up with a concise definitive list of them based on Roger, Stefan, Paul and your findings. Hopefully between that evolving page and the tool it’ll help the developers out!
http://www.sharepointdevwiki.com/display/public/When+to+Dispose+SharePoint+objects
January 30, 2009 at 9:25 am
I agree on what you’re saying for today, that SPDisposeCheck shouldn’t be taken as the de-facto truth, but it is possible for SPDisposeCheck to do a perfect job…eventually, once they program it to cover ALL the rules. In other words, BELIEVE
February 1, 2009 at 5:54 pm
[…] SPDisposeCheck Is Not A Shortcut […]
February 2, 2009 at 12:04 pm
[…] and alert you when SharePoint objects are not being disposed of properly. Keith Dahlby has a good post where he warns people that SPDisposeCheck is not 100% perfect and should not be the end all. After […]
February 14, 2009 at 4:22 am
[…] warning against overdependence notwithstanding, this really is a tool that should be run against any object model […]
February 20, 2009 at 1:20 pm
try that on visual studio post-build events http://sharepointvoodoo.blogspot.com/2009/02/spdisposecheck-tool-how-to-use-in-post.html