Announcing SPDisposeCheck v14.0.4762.1000 Update for SharePoint Development


 

Download location: http://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 (20)

  1. Greg Hurlman says:

    Is /XML working in this release?

  2. Roger Lamb says:

    Yes /XML output is working

  3. panoone says:

    Is there any documentation for use, or is it self-explanatory?

  4. Hikmer says:

    documentation? self-explanatory?  Ha apparently you don't develop for SharePoint much do you?

  5. sis says:

    i see only the old release on the code page.. where is it exactly, please?

  6. Roger Lamb says:

    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.msi  

  7. Jan says:

    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”.

  8. Roger Lamb says:

    Thanks Jan, this has been accepted and under review..

  9. Roger Lamb says:

    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.

  10. Jan says:

    Thanks Roger, looking forward to it. This tool is invaluable in our build process.

  11. Ronald says:

    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.

  12. Ronald says:

    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.

  13. Roger Lamb says:

    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.

  14. Janosch says:

    I encountered a lot of bugs using this add-in. This is happening on VS2010 (but the project im working on does not use the new SharePoint Project Templates)

    1. The "Navigate to error" feature only worked for the very first error in my error list. When I click on every other error I get an "Error navigating to SPDisposeCheckID_XXX" dialogue box popping up.

    2. My debug output of SPDisposeCheck ends with the line "Processing Method Traces…". Is this the expected behaviour? I would have expexted a message indicating that the process has finished, like "Done processing all assemblies" or sth similar.

    3. When I do "Clean Project", SPDisposeCheck errors remain in the error list. I think they shoud be cleared just like the build errors.

    4. In the settings Window, if you want to check a non-leaf node you have to doubleklick on it. I find it not intuitive to have a different behaviour of leaf and non.leaf nodes.

    5. In the settings window, if you check a non-leaf node the child nodes are NOT selected. That is again, not intuitive (why would you select a non-leaf node in this configuration anyway?!)

    6. The settings window can be resized but the content is not scaled, rendering the resizing useless.

    Besides that, its really a good tool. However, 1) is really a show stopper.

  15. Janosch says:

    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.

  16. BinaryJam says:

    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.

  17. phettz says:

    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:)

  18. Long says:

    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.

  19. Mattias says:

    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?

  20. Rich says:

    Long … you have to dispose the webPartManager if I recall