Search Wiki:
Resource Page Description
SPDisposeCheck is a tool that helps developers and administrators check custom SharePoint solutions that use the SharePoint Object Model helping measure against known Microsoft dispose best practices. This tool may not show all memory leaks in your code and may produce false positives which need further review by subject matter experts.

This release includes the SPDisposeCheck.exe and a Visual Studio 2008/2010 Add-In for the Development IDE. SPDisposeCheck.exe 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.

12/13/2010 update: SPDisposeCheck v14.0.4762.1000
SPDisposeCheck tool can be downloaded here.

The SPDisposeCheck updated tool remains a standalone command line utility and we’ve added a Visual Studio 2008/2010 IDE Add-In which calls out to the SPDisposeCheck. This Add-In was originally presented at the SPC 2009 and is now available publically. In addition this version has been tested with both WSS 3.0 + MOSS 2007 and SharePoint 2010 (Foundation and Server) environments.

We have added several checks on when “NOT” to Dispose objects instantiated by SharePoint internally. These newly reported “DO NO DISPOSE” (DND) rules were unreported by SPDisposeCheck v1.3.* . We would encourage you to run the updated SPDisposeCheck tool on all customized SharePoint projects to help identify areas in code which may lead to memory pressure and server stability issues. As a best practice you should consider adding this tool to your SharePoint software development life cycle build process and review its output with a subject matter expert on a regular interval.

Roger Lamb maintains a blog for the SPDisposeCheck team here.

For more information on best practices for SharePoint development please review the MSDN article here
Last edited Dec 14 2010 at 6:07 PM  by rogerla, version 4
colbyafrica wrote  Jan 29 2009 at 7:45 PM  

Anubhav wrote  Jan 30 2009 at 6:20 AM  
Really helpful. Thanks.

Jomit wrote  Jan 30 2009 at 9:27 AM  
Nice tool indeed ! I just posted this on my blog :

But I am having troubles exporting the output to xml ? I tried it with the sample code itself but it just throws some error....

Carol wrote  Jan 30 2009 at 2:14 PM  
Great tool!

However, I have the same trouble with XML output. I tried on assembly where some errors were found and also on clean assembly. The -xml switch trows an exception on both case.

vaibhavmathur wrote  Jan 30 2009 at 4:31 PM  
The tool encounters problem when trying to output xml to a file. Throws the error while trying to "Processing Method Traces..."

ShivaSK wrote  Jan 30 2009 at 10:00 PM  
Having same problem :(

cakriwut wrote  Jan 31 2009 at 3:52 AM  
I have problem with xml option. However it just nice anyway -

michhes wrote  Feb 1 2009 at 4:51 AM  
The tool runs fine without the -xml param... just leave it off and pipe the output to a text file instead (refer note above).

Smeikkie wrote  Feb 2 2009 at 7:58 AM  
Great tool: I posted a topic on my blog
keep up the good work. only writing to a xml file does not work.

bdoc7mcg wrote  Feb 2 2009 at 9:57 PM  
Nice! I also had the XML issue, but piping to a file from the command line worked find for me.
SPDisposeCheck.exe "c:\my folder" >disposecheck.txt

dmcwee wrote  Feb 23 2009 at 4:45 PM  
Great tool, any chance a "black box" dll could be released so it could be integrated with MSBuild tasks?

DGL wrote  Feb 26 2009 at 2:24 PM  
Great Tool, ¡¡cool man!!.

RichardWillis wrote  Feb 26 2009 at 11:55 PM  
I'm the project co-ordinator for the SharePoint Learning Kit at I'd love to use SPDisposeCheck on it, but it check to see if the file name begins with Microsoft (it does) and then if I rename the file, if any namespace begins with Microsoft (they all do) and then skips the assembly. Is there any possibility of adding an option to not skip Microsoft assemblies. And before you ask, we can't change the namespaces as it was originally a Microsoft project and it would break all existing installations.

GandeVijay wrote  Jul 29 2009 at 1:38 PM  
Nice tool, the -xml option did not work.

Bram wrote  Sep 2 2009 at 2:47 PM  
The tool works like a charm and really provides usefull feedback. Although I tried to implement the SPDisposeCheckIgnoreAttribute in my own project within the namespace MyApplication.DisposeCheck.SPDisposeCheckIgnoreAttribute. If I got it right this is mentioned in the SPDispose_Readme.rtf of the SPDisposeCheck tool. It seems after using reflection it checks on the System.Attribute.Type.FullName == "SPDisposeCheck.SPDisposeCheckIgnoreAttribute". Meaning the fullname needs to be equal to SPDisposeCheck.SPDisposeCheckIgnoreAttribute and can't contain your own namespace.

I added an issue for this. Does anyone else have the same or related experience?

StephenDVick wrote  Jan 6 2010 at 3:54 PM  
To see how to run SPDisposeCheck as a build task and automated unit test that can be applied to a check in policy see:


Scoutman wrote  Apr 14 2010 at 12:57 PM  
Hey there , we at the Sharepoint Portuguese User Group developed an Visual Studio 2008/2010 Addin for SharePoint 2007/2010 .
Check it out at
Any questions feel free to ask

boomshanka wrote  Apr 28 2010 at 12:52 PM  
Has anyone tried using SPDisposeCheckRules.dll with Microsoft FxCop 1.36? CodePlex at suggests adding both SPDisposeCheckRules.dll and SPDisposeCheck.exe to the FxCop rules library and the tool does indeed throw errors in the analysis report. But the rule does not show properties in the properties pane - you have to open the message detail to get a description of where the error is located. Is there another way to get the description in the properties pane or do you need to create your own FxCop rule assembly based on SPDisposeCheckRules.dll?

pandrew wrote  Jun 16 2010 at 5:23 PM  
Hi Boomshanka, you can't use SPDisposeCheck rules with FX Cop. The two tools are based on the same original project but FX Cop excludes some infrastructure required by SPDisposeCheck. Please can you take further questions to the Discussion tab where conversations are threaded at


boomshanka wrote  Jun 17 2010 at 12:28 PM  
Thanks Paul - I will

prasadsm wrote  Dec 17 2010 at 11:29 AM  
Thanks Paul for this nice tool.
But I also encountered issue when trying to output xml to a file.


badgej wrote  Jan 11 2011 at 2:19 PM  
The current version (12/13/2010) looks to be reporting a false positive for the disposing of SPWeb from SPContext.Current.Site.RootWeb . According to Roger Lamb's blog posting (, SPSite.RootWeb should not be disposed in favor of disposing the parent SPSite object - and SPContext.Current.Site should not be disposed either.

badgej wrote  Jan 11 2011 at 2:59 PM  
Also, the current version is reporting that SPWeb.ParentWeb should be disposed, which should not be the case (

fewlines4biju wrote  Aug 25 2011 at 4:25 PM  
May be the below tutorial also helpful

alexhayton wrote  Aug 31 2012 at 10:49 AM  
Is the source code for this published anywhere? We would like to edit some of the rules SPDisposeCheck is using and update it to address the last few comments since Dec 2010 but have no way of doing this without a way of compiling it ourselves... Can you post it on Codeplex or somewhere like that?

dmcweeney wrote  Dec 11 2012 at 4:40 PM  
Will an updated version of this tool be released for SharePoint 2013?
Alternatively can you make the source available so we can rebuild ourselves?



JedikOps wrote  Feb 7 2013 at 2:21 PM  
Is it possible to ignore check in constructor?

Tamilarasi wrote  Jul 1 2013 at 4:10 PM  
Thanks..its too usefull

tomvangaever wrote  Sep 23 2013 at 2:11 PM  
Run SPDisposeCheck on all the WSP solutions in specific directory in an automated way via PowerShell:

Matthias_Einig wrote  Oct 9 2013 at 10:49 AM  
Unfortunately SPDisposeCheck does not support .net 4.5 assemblies so it will never show any errors when analyzing SharePoint 2013 projects.
For that reason we developed the SharePoint Code Check (SPCop) which implements all still valid memory disposal rules along with 300 other SharePoint related rules.

Get it for FREE in the Visual Studio Gallery

You can browse all rules in the documentation

or even create your own rules like the guys at

by using the SPCAF/SPCop SDK available here

Let's make our SP code better! :)

Page view tracker