Do not dispose the following listed SharePoint objects explicitlyRemember it’s best practice to regularly review your ULS logs for Dispose() related leaks that have occurred during runtime.. SharePoint Server internally is instrumented to report on Dispose related leaks.
- Do not call list.ParentWeb.Dispose()
- Problems may occur when SPContext.Web has equality to the SPContext.Web.. make sure you dispose of SPSite and it will cleanup sub webs automatically
- When used with WSS 3.0 you must call Dispose(), with SharePoint Foundation 2010 you don’t.
- Event Receivers and properties.OpenWeb()
- WSS 3.0: When you call properties.OpenWeb() the returned SPWeb will need to call Dispose()
- SharePoint Foundation 2010: Use the newly introduced SPItemEventProperties.Web property instead of SPItemEventProperties.OpenWeb() for better performance and to avoid the need to call Dispose().