Memory Leak - Disposing SPSite and SPWeb?

David Lozzi
  • Memory Leak - Disposing SPSite and SPWeb? David Lozzi

    So I read through another post here Disposal of SPWebs created using SPSite.OpenWeb().

    Currently I only dispose of the SPSite object, and from my understanding whe SPSite disposes any opened SPWeb should dispose as well. It appears best practice is to dispose of each SPWeb as well. I will do so.

    My reason for this post is this: what would a memory leak look like? I have a timer job which runs every 2 minutes and processes some list items. Again, i am only disposing of the SPSite object, not the SPWeb object. After letting it run for about a week on dev, the sqlserver.exe process was around 1.7GB of used memory. SharePoint started to error Out of Memory. I have since restarted SQL and it's down to 320MB of memory. I don't know how much it was before I installed the timer job, but we weren't getting these errors then.

    Am I seeing a memory leak in sqlserver due to me not closing SPWeb? Or would a SharePoint memory leak occur in the w3wp process? Any clarity is greatly appreciated!


  • A memory leak will manifest itself in whatever is the host process for the code which has the leak. In the case of SharePoint code, this won't be the SQL process - most likely what you're seeing here is simply down to the fact that SQL generally consumes as much memory as it can (i.e. whatever isn't being scavenged/used by other processes). You can peg it though if you wish, I sometimes do this (e.g. on dev VMs).

    So you might see a leak due to SharePoint code in:

    • w3wp.exe for code running from a web page
    • Owstimer.exe for a timer job
    • STSADM.exe for a custom STSADM command
    • The process for a custom exe e.g. in the case of a console app


dispose spweb
Related questions and answers
  • Is there any way in SharePoint 2010 to get the Distinct values of a property across all users? For example, I want a list of all Departments in the Profile Store. In SQL I can do SELECT DISTINCT(PropertyVal) FROM [ProfileDB].[dbo].[UserProfileValue] WHERE PropertyID = 14 but accessing the SQL Database is a big no-no of course, so I wonder if there is something in the object model? Note that accessing the User Information List on an SPSite is not good enough, as only a fraction of all users is in that list. I want to get it directly from the Profile Store. I do not want to loop through

  • SharePoint provides an option in Create New WebApplication page that says Restart IIS Automatically. This restarts IIS on all servers of the farm. What can I do to trigger this programmatically from my Application Page (ASP.NET)? Is there a timer job for this? Is there anything in the API? do I have to create "iisreset" process and pass it the name of servers?

  • and they do not work. I have found the code that I can place in the machine.config file that turns off the check, but I would like to figure out what is going on with this. I have ensured that debug is set to false in the web.config file as well. It is only my user controls that are causing the issue, but I do not know why. So it would be nice if there was a list of known .Net assembles that were...I have created several custom user controls that I added to the Redering templates of some forms in a custom solution for WSS 3. Most of these templates have codebehind and they all are correctly

  • ) > SPWeb.SPWebConstructor(SPSite, string, bool, SPRequest) > SPSite.AddToOpenedWebs(SPWeb) According to Roger Lamb, SPWebs returned by SPSite.OpenWeb() SHOULD be disposed (I am assuming this applies to all overloads for SPSite.OpenWeb()), but based on my findings, I don't see why, as it seems to me that any SPWeb opened using the SPSite.OpenWeb(string) method is automatically disposed (closed) when the SPSite on which OpenWeb() was called is disposed. I believe it's quite likely I have made some mistake in my thinking somewhere (who am I to question Roger Lamb?), but at this moment I don't know

  • I have run into a problem several times now where I have developed a custom timer job, and I want my site collection administrators to manage the schedule of this job with a custom application page... the Central Admin app pool account can write to the config database But then we lose the whole point - I want my site collection administrators to be able to manage the schedule! The only alternative solution I can think of is to have another timerjob that polls some kind of queue (for example a sharepoint list in my site collection) for new timerjobs to create, and creates it if an item has been added

  • post Infrastructure Update - in my situation it was applying SP2 but it might have been one of the culmlative updates after IU A search pre-SP2 using contentclass:STS_Site as a filter will list all... only site collections/sites using non-publishing templates. All other content is availble e.g. documents, lists Has anyone else come across this? UPDATE 08/05/10: I have been doing some further... in the index under the contentclass:STS_Site and the sites (SPWeb's) are contentclass:STS_Web. The following people seem to have come across this issue and assumed it was just a limitation. I think

  • or automatic creation of an accident list item. Now the process will need to have a set of official forms filled in by various people. This is where I find SharePoint limiting me with it's document centric...SharePoint workflow by nature is document centric in that you have to have a 'thing'; A object for the workflow to run on. This object can be a document, form or simple list item but this thing has to exist as the anchor and context of the workflow. What I've started thinking about is a more abstract sort of workflow and how it would be useful in SharePoint. Workflows are user driven processes

  • I have been developing on SP 2010 for a while now. Mostly I have been working with the Client Object Model. Though I am at a point where I need to read out the UserProfiles from inside SharePoint. I see no other way to do this than to make a custom WCFService and deploy it to SharePoint. So that is what I did. I made an "Empty SharePoint Project" and added the mapped "ISAPI" folder. The code...; } This service gives a TimeOut error... When I delete the following line the TimeOut is fixed if (profile["FirstName"] != null) { } So I can only read out

  • I am using SharePoint Server 2007 Enterprise with Windows Server 2008 Enterprise. I have deployed a publishing portal. I am developing a ASP.Net web application using VSTS 2008 + C# + .Net 3.5 + ASP.Net + SharePoint Server 2007 SDK. Here is my code snippets and I got error -- "Updates are currently disallowed on GET requests". Any ideas how to fix? Microsoft.SharePoint.SPException: Updates are currently disallowed on GET requests. To allow updates on a GET, set the 'AllowUnsafeUpdates' property on SPWeb. protected void Page_Load(object sender, EventArgs e) { try

Data information