Thursday, January 29, 2009

Disposing SharePoint 2007 and WSS 3.0 Objects

Here is an excellent article by Roger Lamb explaining the various design patterns to be used for disposing various SharePoint and WSS objects before deploying to the production environment.
Some of these may cause serious implications and memory leaks if not addressed correctly. In particular there are 3 objects to be taken care of,  Microsoft.SharePoint.SPSite , Microsoft.SharePoint.SPWeb and Microsoft.SharePoint.Publishing

There are also couple of White Papers by Scott Harris's on MSDN for more details:
Best Practices: Using Disposable Windows SharePoint Services Objects
Best Practices: Common Coding Issues When Using the SharePoint Object Model.

Also recently there is a Tool published on the MSDN Code Gallery which provides assistance in correctly disposing of certain SharePoint objects to help us follow these best practices.

SPDisposeCheck.exe is a command line tool which takes the path to a managed .DLL or .EXE or the path to a directory containing many managed assemblies. It will recursively search for and analyze each managed module attempting to detect coding patterns based on the MDSN article.

Below is the screenshot of the actual output generated which running the spdisposecheck on the sample exe. Reading the command line output is a bit tedious. Although the documentation states that this tools has an -xml option to output the details to an xml file but it doesn't seem to work for me..SpDisposeCheck


GOPI said...


Nice article..Do you know where can I find the 64bit version of this tool?
Thanks in advance..

Gopi Ega

Jomit Vaghela said...

Haven't tried this on 64bit machine but will find out and let you now