I’ve created a static analysis ruleset for SPDisposeCheck!
SPDisposeCheck is a valuable tool developed by a small team within Microsoft Premier Support led by Roger Lamb that inspects an assembly to ensure that SharePoint API objects are properly disposed. Failure to properly dispose SharePoint API objects can cause memory leaks. The SPDisposeCheck tool can be downloaded here:
The source and compiled versions are available on CodePlex:
Here are the steps to get this up and running on your SharePoint projects:
Copy the SPDisposeCheck SPDisposeCheckRules.dll and the SPDisposeCheck.exe to your local static analysis rules folder.
Example: C:\Program Files\Microsoft Visual Studio 9.0\Team Tools\Static Analysis Tools\FxCop\Rules
Open a SharePoint project and select Project Properties. Select the Code Analysis tab. You should see a new ruleset available called SPDisposeCheck Rules.
If you select Enable Code Analysis on Builds and Treat Warnings as Error for the SPDisposeCheck ruleset, developers should see any SPDispose errors on build for any code added to the solution.