It is a well know fact that the SPSite and SPWeb objects need to be properly disposed of when using them in your API coding.  MSDN and the SDK typically tells you that when you see anything referencing those 2 objects.  The reason is that behind the scenes they have a reference  to a SPRequest object which uses a SharePoint COM object which isn't automagically disposed for you.  All the examples on MSDN and in the SDK show how to use the "using" statement, or manually calling "Dispose()" on the objects, but they don't really offer any other info than that.

Today I ran across a few REALLY good blog postings about this topc.  The first, by Stefan Gobner, shows how to do some troubleshooting, which is DEFINETELY worth a read.  He shows how you can go into the ULS logs, find certain error messages, and really track down the code that you wrote to find where you might not properly be disposing of the suspect objects.  You can find that article here, I strongly suggest reading it.

The second article, written by Roger Lamb, is actually linked from Stefan's blog and goes into a LOT more detail about pretty much all the objects that need to be disposed, and shows a lot more than MSDN/SDK does.  You can find that article here.


Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2014 Tony Testa's World