Might as well dive right in and make the inaugural posting useful…
Anyone who’s done some development work with SharePoint probably already knows about this article, but I wanted to place it here for reference:
Best Practices: Using Disposable Windows SharePoint Services Objects
Review the article very carefully… there are things we do often such as getting to an SPSite’s RootWeb, like this:
SPSite site = SPControl.GetContextSite(HttpContext.Current); SPWeb rootWeb = site.RootWeb;
In this case, it’s pretty obvious (based on the article) that we need to call:
rootWeb.Dispose();
However, if you were to access a property like this:
string rootWebTitle = site.RootWeb.Title;
the article states that you should call
site.RootWeb.Dispose();
which is not obvious, in my opinion. So to keep/ensure your SharePoint site/application runs as smoothly as possible, clean up after yourself!
EDIT (September 2008):
This is kind of old news by now, but here is another article from Andrew Woodward (which references 3 articles other than MSDN). Worthy to note that we need to properly Close() all PublishingWeb objects as well.
http://www.21apps.com/2008/02/sharepoint-ate-all-my-memory-dealing.html
Roger Lamb’s blog has some really good examples. Also make sure to read the comments.
http://blogs.msdn.com/rogerla/archive/2008/02/12/sharepoint-2007-and-wss-3-0-dispose-patterns-by-example.aspx
Stefan Gossner gives a pretty good in-depth look at how memory is consumed.
http://blogs.technet.com/stefan_gossner/archive/2007/11/26/dealing-with-memory-pressure-problems-in-moss-wss.aspx
Finally, a post about application pool/worker process recycling and SharePoint.
http://blogs.msdn.com/steveshe/archive/2007/12/17/overlapped-recycling-and-sharepoint-why-sharepoint-requires-it.aspx