January 2009 - Posts

SharePoint Dispose Checker - Even more useful than expected
29 January 09 04:53 PM | Aaron Robertson-Hodders SharePoint Blog

By now you have probably heard that the SharePoint Dispose Checker has been released. It's an excellent tool for checking you are disposing of your SharePoint objects correctly!

I downloaded it this morning as soon as I read about it just to see if I have really been as concientious as I thought I had. Smile

Turns out, according to the output from the tool that I have done a pretty good job of cleaning up after myself. In the 10,000 lines of code mostly devoted to interrogating the SharePoint structure there were only 15 issues raised and all but 2 were false positives - darn those UserProfile personal site objects!

What did surprise me was that the false positives were actually quite useful in bringing to light some areas of the code that were less than perfect. For example, where I had used two instances of the same site in the same code block where one would have sufficed or where although objects were disposed of in a finally block, there were instances where exceptions further up in the code could have lead to one of several objects not being disposed correctly. It also highlighted some areas where although there was a disposal in the finally block the code looked much neater if it was replaced with a using block.

I'd recommend that you run the tool over your code no matter how careful you are for the review value alone.

I'm going to put this into my projects build events - and if I get really keen perhaps I'll parse the output to remove the known false positives automatically.

I wonder why it won't run against the assemblies in the ISAPI directory... Wink


Posted on SharePoint Blogs Del.icio.us | Digg It | Technorati | Blinklist | Furl | reddit | DotNetKicks