Should I call Dispose on SPWeb.ParentWeb?

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):

“SPWeb.ParentWeb Property

Updated Guidance

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().

Unknown's avatar

About Bernado

Based in Australia, I am a freelance SharePoint and Dynamics CRM developer. I love developing innovative solutions that address business and everyday problems. Feel free to contact me if you think I can help you with your SharePoint or CRM implementation.
This entry was posted in SharePoint 2010. Bookmark the permalink.

Leave a comment