Disposing of Objects Correctly in MOSS or WSS 3.0

One of the big "gotchas" in coding against the SharePoint Object Model is not disposing of resources properly.  In relatively little time, you can find that your server is cycling itself to free up resources, with no apparent reason.  The first thing you should check is your own code.

Roger Lamb has written an excellent, in-depth article called SharePoint 2007 and WSS 3.0 Dispose Patterns by Example about how to fix these issues.  When my client had memory leak issues, they first wanted to blame the third party Web Parts that they had installed and they uninstalled them.  No joy.  After much back and forth with Microsoft (I was out of the loop on much of this), they were pointed to Roger’s post.  Making all of the changes that Roger recommended solved the problems.

These weren’t "big deal" Web Parts, either, but they were called frequently.  Every time that they were called, they held onto a little bit of memory until everything was brought to its knees.  No matter that they were running big iron for their farm; memory is finite, and eventually you will use it all up.

Another excellent resource is an article that Roger references in his post from Stefan Goßner entitled Dealing with Memory Pressure problems in MOSS/WSS.

While computing has changed drastically since my early days of writing assembly and FORTRAN, smart use of memory never goes out of style!


  1. Have you ever seen memory leaks using a DVWP across sites? It seems my colleague has this issue and since it’s written in XSL, I don’t know how to fix it.

    • Josey:

      No, I’ve never seen memory leaks with a DVWP. I’d be surprised in the product team would have allowed that to happen (but stranger things happen, as we both know).

      Since you haven’t given any details about your issue, it’s hard to say what might be happening. howver, be sure to read my post about possible issues with the August CU. It’s not a memory leak, but an intentional stack overflow.



Have a thought or opinion?