Announcing SPDisposeCheck v14.0.4762.1000 Update for SharePoint Development
Download location: https://code.msdn.microsoft.com/spdisposecheck
Update Summary:
I’m happy to announce SPDisposeCheck v14.0.4762.1000 was updated and released today 12/13/2010.
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.
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.
Finally, 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.
I plan on posting a follow up on some code examples of when not to dispose object following this initial announcement.
Reference list of Do Not Dispose Rules checked:
- SPDisposeCheckID_600 = 600, //DO NOT DISPOSE: SPListEventProperties.Web
- SPDisposeCheckID_605 = 605, //DO NOT DISPOSE: SPWebEventProperties.Web
- SPDisposeCheckID_610 = 610, //DO NOT DISPOSE: SPItemEventProperties.Web
- SPDisposeCheckID_615 = 615, //DO NOT DISPOSE: SPItemEventProperties.ListItem.Web
- SPDisposeCheckID_620 = 620, //DO NOT DISPOSE: SPItemEventProperties.Web.Site
- SPDisposeCheckID_625 = 625, //DO NOT DISPOSE: SPItemEventProperties.ListItem.Web.Site
- SPDisposeCheckID_630 = 630, //DO NOT DISPOSE: SPFeatureReceiverProperties.Feature.Parent
- SPDisposeCheckID_635 = 635, //DO NOT DISPOSE: SPList.ParentWeb & SPListEventProperties.List.Web
- SPDisposeCheckID_640 = 640, //DO NOT DISPOSE: SPWeb.ParentWeb
- SPDisposeCheckID_645 = 645, //DO NOT DISPOSE: SPContext.Site & SPContext.Current.Site
- SPDisposeCheckID_650 = 650, //DO NOT DISPOSE: SPContext.Web & SPContext.Current.Web
- SPDisposeCheckID_655 = 655, //DO NOT DISPOSE: SPSite.RootWeb (Covers -v1 SPSite.LockIssue, SPSite.Owner, SPSite.SecondaryContact checks)
- SPDisposeCheckID_660 = 660, //DO NOT DISPOSE: SPControl.GetContextWeb(..)
- SPDisposeCheckID_665 = 665, //DO NOT DISPOSE: SPControl.GetContextSite(..)
- SPDisposeCheckID_670 = 670, //DO NOT DISPOSE: Microsoft.SharePoint.Administration.SPSiteAdministration.OpenWeb() + 2010
- SPDisposeCheckID_700 = 700, // Microsoft.SharePoint.SPItemEventProperties.OpenWeb() on Sharepoint 2010
Special thanks to the SPDisposeCheck core development team: Sean Thompson, Greg Varveris, Paul Andrew, and Stefan Goßner !
Comments
Anonymous
December 13, 2010
Is /XML working in this release?Anonymous
December 13, 2010
Yes /XML output is workingAnonymous
December 13, 2010
Is there any documentation for use, or is it self-explanatory?Anonymous
December 13, 2010
documentation? self-explanatory? Ha apparently you don't develop for SharePoint much do you?Anonymous
December 13, 2010
i see only the old release on the code page.. where is it exactly, please?Anonymous
December 14, 2010
Looks like there may have been some provisioning issues with the code.msdn.microsoft.com site, all looks corrected now. You can verify the correct version should be v14.0.4762.1000 during the readme or looking at the version info of the spdisposecheck.exe once installed. A direct link is here download.microsoft.com/.../SPDisposeCheck.msiAnonymous
December 14, 2010
Had issues with updating our MOSS project with the latest tool. For the following code: using (SPSite rootSite = new SPSite(siteUrl)) { using (SPWeb rootWeb = rootSite.RootWeb) { ... } } It complained that “Statement: rootWeb.{System.IDisposable}Dispose(). Dispose should not be called on this object.” Obviously if I removed the using statement for SPWeb gave me the “Disposable type not disposed: Microsoft.SharePoint.SPWeb”.Anonymous
December 14, 2010
Thanks Jan, this has been accepted and under review..Anonymous
December 14, 2010
Jan: We have confirmed SPDisposeCheck v14 "SPWeb rootWeb = rootSite.RootWeb" should not be reporting a rule error.. we will be planning an update in January and collecting any additional feedback.Anonymous
December 14, 2010
The comment has been removedAnonymous
December 15, 2010
I am a bit confused about the last two Do Not Dispose rules. SPSiteAdministration.OpenWeb()? Can't find this method, and normally OpenWeb does create a new SPWeb object, that should be disposed. The last rule, again: OpenWeb creates a new SPWeb object, I have checked this with Reflector. It just calls an OpenWeb(with url) on the SPSite object. Should be disposed, I believe... SPDisposeCheck is a great tool, if I see a project that doesn't use it, I will introduce it. Sadly a lot of mistakes are still made in this area. That is why this tool is so useful.Anonymous
December 15, 2010
Looked into it a bit more: The SPItemEventProperties.OpenWeb() should not be used with SP2010, .SPItemEventProperties.Web should be used instead. Still if you use OpenWeb, for example in SP2007, I think you should dispose the returned object.Anonymous
December 15, 2010
Ronald, thanks for the feedback! I'll take a look at the 2007/2010 logic closer and see if the wording of the output for this can be more relevant based on SP version.Anonymous
March 13, 2011
The comment has been removedAnonymous
March 13, 2011
SPDisposeCheck gives me error code 655 on the following snippet: SPWeb propertyWeb = fromRootweb ? s.RootWeb : s.OpenWeb(_spContext.Web.ID); try { config.ReadXml(new StringReader(propertyWeb.Properties[getWebPropertyName(listGuid)])); Log.Debug("Config loadedn" + config.GetXml()); } finally { if( !fromRootweb && propertyWeb != null ) propertyWeb.Dispose(); } This is IMHO wrong, because I only dispose if OpenWeb has been called.Anonymous
April 06, 2011
Hi, having ran this a few times it sometimes does report false positives, is there a way of marking the offending code with perhaps a comment to tell the checker, ok they've marked this as ignore it's their worry now ? This would mean I can then just take the output and generate tasks in TFS to go fix/investigate knowing Im not repeating myself.Anonymous
April 09, 2011
Tnx for this tool and an interesting blog! I'm still learning C# and SharePoint, so this helps me alot on the right path for doing it properly:)Anonymous
May 05, 2013
void SPLimitedWebPartManagerLeak() { using (SPSite siteCollection = new SPSite("http://moss")) { using (SPWeb web = siteCollection.OpenWeb()) { SPFile page = web.GetFile("Source_Folder_Name/Source_Page"); SPLimitedWebPartManager webPartManager = page.GetLimitedWebPartManager(PersonalizationScope.Shared); // SPWeb object webPartManager.Web leaked. } // SPWeb object web.Dispose() automatically called. } // SPSite object siteCollection.Dispose() automatically called. } The latest version cannot detect this memory leak, could you help fix this? thank you.Anonymous
June 02, 2013
I get a circular errors for RootWeb property. First i had a using around the property and this tool said i should not dispose it. I removed the using and now the tool say i should dispose it... What is correct and why is it not working as it should?Anonymous
December 06, 2013
Long ... you have to dispose the webPartManager if I recall