SharePoint: What Should I Dispose?
When starting with SharePoint development, a common question is “Which objects should I dispose?”. This is crucial because SharePoint leaks approximately 1 MB of memory per undisposed IDisposable object. For components like menus, this can quickly add up to 10 MB per page load. While the MSDN documentation provides comprehensive guidance, here’s the quick answer: In your WebPart, dispose of all SPWeb and SPSite objects except: SPContext.Current.Site SPContext.Current.Web SPContext.Current.Site.RootWeb For Features, dispose of all SPWeb and SPSite objects except those provided in your “properties” variable. ...