Search This Blog

Friday 27 September 2013

Object Disposal best practice

If we are not performing any operations on the SPSite object, we can write as in the following code example.

void CombiningCallsBestPractice()
{
    using (SPSite siteCollection = new SPSite(SPContext.Current.Web.Url))
    using (SPWeb web = siteCollection.OpenWeb())
        {
        //Perform operations on site.
        } // SPWeb object web.Dispose() automatically called; SPSite object
          // siteCollection.Dispose() automatically called.
}

No comments:

Post a Comment