Cleaning up the resources in Sharepoint Programming

Here are some tips for SharePoint programming for Cleaning up the resources :-
Objects that implement IDisposable

SPSite mySite= new SPSite(“http://server”) ;

Some objects are created without “New” operator (Hidden)
SPSite mySite= new SPSite(“http://server”) ;
string str= mySite.RootWeb.Url;

Some objects don’t need to be disposed
SPGroupsGrp= spWeb.AssociatedMemberGroup;

Don’t call Dispose/Close on a shared resource
SPSite site = SPControl.GetContextSite(this.Context);
SPWeb web = SPControl.GetContextWeb(this.Context);
SPSite mySite= SPContext.Current.Site;
SPWeb myWeb= SPContext.Current.Web;

No comments: