I was coding away and wondered if I should call Dispose the parentWeb object below?
SPWeb parentWeb = web.ParentWeb; parentWeb.Dispose(); //Should I?
I found some official guidance on this and thought I’d blog it here, partly to help jolt my memory later on.
The short answer is: No, calling Dispose() is not required on SPWeb.ParentWeb:
From MSDN (http://msdn.microsoft.com/en-us/library/aa973248(v=office.12).aspx):
An earlier version of this article recommended that the calling application should dispose of the SPWeb.ParentWeb. This is no longer the official guidance. The dispose cleanup is handled automatically by the SharePoint framework.”
Update: What about SPSite.RootWeb – should I call Dispose() on that? Official guidance (also in the above link) is: NO. Do not call SPSite.RootWeb.Dispose().