I think the second line should not use using because its in the sp context.
using (SPSite SiteCol = new SPSite(SPContext.Current.Web.Url))
{
using (SPWeb UpdateCurrentweb = SiteCol.RootWeb)
{
|
I think the second line should not use using because its in the sp context.
|
|||
|
|
|
No it's not good coding practice, but the issue isn't wrong disposal, but maybe wrong web and bad performance Disposal Wrong web Performance |
|||
|
|
|
No explicit dispose required for RootWeb. The SPSite you create is automatically disposed by implementing using(). The RootWeb will be disposed by SPSite. So you can write :
|
|||
|
|
|
Actually, your first using row creates a new SPSite istance that (as far as I know) has no memory whatsoever of having begin constructed from a url taken from the SPContext - so the .RootWeb instance should be a different instance from the one in the context. Anyway, the "latest" Sharepoint Dispose/Do Not Dispose guidance reports that the .RootWeb property of an SPSite object no longer needs explicit disposal, so I would just skip that. For further reference you can look here and here on Roger blog, or here on msdn.
Notice that the linked documentation from Roger Lamb also reports that
I suppose that equality should be read as "same instance", so that shouldn't be your case,but since you don't need to dispose the .RootWeb instance anyway... better safe than sorry. |
|||
|
|
|
If the second line was as shown below
Then, it should have been corrected to
In short, Visit the msdn article about disposing SharePoint objects for more details and also a similar post from SPSE where you could see different approaches while coding. |
||||
|
|