SharePoint Memory Leak

I was recently struggling with a memory leak somewhere in my code.  My code which was running in the _LAYOUTS directory was handling content types across sites/lists in a SharePoint configuration. 

On my local machine with a small number of lists/sites everything appeared to be fine, but when running on a test server I could see the memory in use on the server to jump up by several MB every couple of seconds.  After a few minutes the memory on the server could be up to a over a GB.  Eventually an OutOfMemory exception would be thrown.

I pulled all my code apart and ran some profiling tools to find the problem and it turned out to be an SPWeb which was being created and not being closed (unbeknown to me).  So it was an easy solution once found.

I found this MSDN link very useful while looking into this and thought it would be worth highlighting for any developers working with SharePoint: 

This entry was posted in Memory/Performance, SharePoint. Bookmark the permalink.

4 Responses to SharePoint Memory Leak

  1. J says:

    I think I’m in the same situation. Do you remember what code caused the SPWeb to be instantiated?

  2. Shiva Krishna says:


    Even I too was working on Sharepoint and faced quite a few issues with the Sharepoint memory leaks.

    I have listed out all our production issues and put forth for the users so that the same wouldnt happen with any one.


    In case you require more info just comment on the post so that i would reply on this.

  3. Ali says:

    Can you please say what profiling tools you used to find out the problem?

  4. F*ckin? tremendous issues here. I am very glad to see your article. Thank you a lot and i’m looking forward to contact you. Will you kindly drop me a e-mail?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s