SP0001 - Dispose created SPSite or SPWeb objects

When you create a SPSite or a SPWeb object with a new operator, the creating application must dispose of it.

SP0002 - Dispose SPWeb returned from a method

SharePoint methods that return other SPWeb objects (such as SPSite.OpenWeb) create new items and should be disposed of.

SP0003 - Do not dispose SPSite.RootWeb and SPWeb.ParentWeb properties

The SPSite.RootWeb property and SPWeb.ParentWeb property no longer require Dispose() to be called on itself as previously indicated.

SP0004 - Dispose SPSite returned from the SPSiteCollection.Add method

The SPSiteCollection.Add method creates and returns a new SPSite object. You should dispose of any SPSite object returned from the SPSiteCollection.Add method.

SP0005 - Dispose SPSite returned from the SPSiteCollection [] index operator

The SPSiteCollection [] index operator returns a new SPSite object for each access. An SPSite instance is created even if that object has already been accessed. The recommended fix is to place a Dispose() at the end of each loop.

SP0006 - Dispose SPWeb returned from the SPSite.AllWebs.Add method

The SPSite.AllWebs.Add method(or SPWebCollection.Add) creates and returns an SPWeb object. You should dispose of any SPWeb object returned from SPSite.AllWebs.Add.

SP0007 - Dispose SPWeb returned from the SPSite.AllWebs [] index operator

The SPSite.AllWebs [] index operator returns a new SPWeb instance each time it is accessed. An object is created during the indexing operation even if that object has already been accessed. If not properly closed, the following code samples leave an SPWeb object in the .NET Framework garbage collector.

SP0008 - Do not dispose SPSite.RootWeb when using SPSite.LockIssue, SPSite.Owner or SPSite.SecondaryContact properties

The following properties reference data from the top-level Web site and use the SPSite.RootWeb property:
  • SPSite.LockIssue
  • SPSite.Owner
  • SPSite.SecondaryContact
For more information, see the discussion of SPSite.RootWeb. Based on the updated Microsoft guidance for RootWeb there is no longer a requirement to explicitly Dispose on any of these properties.

SP0009 - Dispose SPWeb returned from the SPWeb.Webs.Add method

The SPWeb.Webs.Add method creates and returns a new SPWeb object. You should dispose of any SPWeb object returned from this method call.

SP0010 - Dispose SPWeb returned from the SPWeb.Webs [] index operator

The SPWeb.Webs [] index operator returns a new SPWeb for each access. A new SPWeb is created by calling the OpenWeb method even if that object has already been accessed.

SP0011 - Dispose SPWeb returned from the Area.Web property

The Area.Web property returns a new SPWeb object each time it is accessed. Any use of the Area.Web property should have a corresponding call to the Dispose method.

SP0012 - Dispose the SPLimitedWebPartManager.Web property

When using the SPLimitedWebPartManager class a reference to an internal SPWeb object which needs to be disposed.

SP0013 - Do not dispose SPList.ParentWeb when using the SPList.BreakRoleInheritance method

When using the SPList.BreakRoleInheritance() method, an internal call to ParentWeb property is called. SPList.BreakRoleInheritance() method no longer requires list.ParentWeb.Dispose() to be executed after calling BreakRoleInheritance() due to the updated ParentWeb guidance.

SP0014 - Close PublishingWeb returned from the PublishingWeb.GetPublishingWebs [] index operator

When using the PublishingWeb class, GetPublishingWebs method which returns a PublishingWebCollection you are required to call Close on the enumerated innerPubWeb objects. Note that when you are only calling GetPublishingWeb method without using the GetPublishingWebs collection you are not required to explicitly call close.

SP0015 - Do not dispose SPSite and SPWeb returned from the GetContextSite and GetContextWeb methods

GetContextSite(Context) and GetContextWeb(Context) methods return SPSite and SPWeb objects respectively that DO NOT need a call to Dispose() and will be disposed automatically by SharePoint.

SP0016 - Do not dispose SPSite and SPWeb returned from the SPContext.Current.Site, SPContext.Site, SPContext.Current.Web and SPContext.Web properties

SPContext.Current.Site and SPContext.Site as well as SPContext.Current.Web and SPContext.Web properties return SPSite and SPWeb objects respectively that DO NOT need a call to Dispose and will be disposed automatically by SharePoint.

SP0017 - Do not dispose SPSite and SPWeb returned from the SPFeature.Parent property

SPFeature.Parent property return SPSite or SPWeb objects that are get from SPContext and that DO NOT need a call to Dispose and will be disposed automatically by SharePoint.

SP0018 - Close PublishingWeb returned from the PublishingWeb.GetVariation method

PublishingWeb.GetVariation() method returns a PublishingWeb object which which needs to be explicitly closed.

SP0019 - Dispose SPSite returned from the UserProfiles.PersonalSite property

UserProfiles.PersonalSite requires a Dispose() call before leaving scope if you use the property in your code.

Last edited Apr 13, 2009 at 7:50 AM by Adrien, version 4

Comments

No comments yet.