No me hago responsable si copiaste mal algún código que sale en las páginas de este sitio.
Ojalá sea de ayuda para más de alguno este sitio.
Se agradece si deja algún comentario.

jueves, 16 de diciembre de 2010

SPDisposeCheck

http://code.msdn.microsoft.com/SPDisposeCheck

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

http://blogs.technet.com/b/stefan_gossner/archive/2010/12/15/first-issue-with-spdisposecheck-has-been-identified-by-the-community.aspx

First issue with SPDisposeCheck has been identified by the community

 Stefan Goßner 15 Dec 2010 7:42 AM 0
One day out and we already have received feedback about a problem with SPDisposeCheck. ;-)

Here are the details:

Code like the one below is not recommended as it disposes the RootWeb - that is correctly identified by SPDisposeCheck!

        public void DND_RootWeb()
        {
            using (SPSite siteCollection = new SPSite("http://intranet.contoso.com"))
            {
                // Do Not Dispose Example
                using (SPWeb rootWeb = siteCollection.RootWeb)       // SPDisposeCheck reports "do not dispose" correctly
                {
                    string url = rootWeb.Url;
                }
            }
        }
But if a developer now changes his code like the following:

        public void DND_RootWeb2()
        {
            using (SPSite siteCollection = new SPSite("http://intranet.contoso.com"))
            {
                // Do Not Dispose Example
                SPWeb rootWeb = siteCollection.RootWeb;       // this should be allowed, but SPDisposeCheck reports warning
            }
        }
Then you suddenly get a warning like this:

SPDisposeCheckID_140:  Disposeable type not disposed: Microsoft.SharePoint.SPWeb ...

That warning is actually incorrect as in this situation it is recommended NOT to dispose the RootWeb.

The issue will be fixed in the next drop of SPDisposeCheck which is expected to be released in January.

No hay comentarios:

Publicar un comentario