Tuesday, January 1, 2013

Which SharePoint 2010 objects should not be disposed

In this post we will discuss about what are the SharePoint objects which should not be disposed explicitly.

You can also check my previous posts on Detecting Memory Leaks in SharePoint 2010, Disposing SharePoint Objects and Client Object Model SharePoint 2010.

Below are some objects which should not disposed:

SPSite site = SPContext.Current.Site;

SPWeb rootWeb = site.RootWeb;

SPWeb web = SPContext.Web;

SPWeb web = SPContext.Current.Web;

SPSite site = SPContext.Site;

SPSite site = SPContext.Current.Site;

Next we should not dispose objects used in a feature receiver like:

public override void FeatureActivated(SPFeatureReceiverProperties properties)
SPWeb web = properties.Feature.Parent as SPWeb;

The below objects should not be disposed.





- Those objects used with personal pages:

The Microsoft.SharePoint.Portal.WebControls.IPersonalPage interface has two properties that return SPSite and SPWeb objects, respectively: IPersonalPage.PersonalSite and IPersonalPage.PersonalWeb.

No comments:

Post a Comment