Today I had the privilege of fixing a memory leak in our SiteBuilder tool. It is a horrible job. I thought I knew in which cases to manually Dispose SharePoint objects like SPSite and SPWeb. Turns out I didn’t and I missed a number of them. Which resulted in a memory leak in our tool. In my post I will summarize the links that helped me most to fix it. My advise is to read this! Even if you think you know what you are doing, like I did :-).
The most important is the weblog of Roger Lamb. It has very good examples and is updated every now and then. This MSDN article contains a lot of best practises and examples.
And in case it is too late and you need to get a leak from an existing piece of code, the tips of Stefan Goßner really help. In his post he describes how to use SharePoint ULS logs to find your leak(s). I found mine by setting the “SPRequestStackTrace” value in the registry and analyzing the ULS logs. The ones I missed were the SPList.BreakRoleInheritance and the disposal of the Web property of the SPLimitedWebPartManager.
And now I am on my way to Paradiso, the best venue for live music in the Netherlands!