Suppose we have code:
CASE 1:
using (SPSite site = new SPSite(SPContext.Current.Web.Url))
{
SPWeb web = site.RootWeb;
}
Do we need to dispose the SPWeb in this case?
CASE 2:
using (SPSite site = new SPSite(SPContext.Current.Web.Url))
{
SPWeb web = new SPSite(SPContext.Current.Web.Url).OpenWeb();
}
Do we need to dispose the SPWeb in this case? Or does it get automatically disposed after the using block disposes the SPSite object?
usingstatement.usingis equivalent totry catch finally– Nadeem Yousuf-AIS Apr 23 '14 at 05:25RootWebis disposed by SPSite? When decompiling the SharePoint DLL I can't see where it is disposed at all. I thinkm_openedWebsare all disposed of properly, butRootWebis not part of these. I know it is disposed, I just can't see where it is done – eirikb Apr 23 '14 at 06:10