Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have the SPRequest object was not disposed error.

12/10/2013 14:21:03.03  w3wp.exe (0x260C)                           0x1700  SharePoint Foundation           Performance                     nask    Monitorable An SPRequest object was not disposed before the end of this thread.  To avoid wasting system resources, dispose of this object or its parent (such as an SPSite or SPWeb) as soon as you are done using it.  This object will now be disposed.  Allocation Id: {D54D46CA-238E-4E42-8F2B-FB04C280C8DD}  To determine where this object was allocated, set Microsoft.SharePoint.Administration.SPWebService.ContentService.CollectSPRequestAllocationCallStacks = true.   28e11e24-7b30-444d-98b9-1056cfc7f62a

At the end of which it says to determine where this object was allocated, set

Microsoft.SharePoint.Administration.SPWebService.ContentService.CollectSPRequestAllocationCallStacks = true

I have done this using this powershell

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$file = $Env:CommonProgramFiles+"\Microsoft Shared\Web Server Extensions\14\ISAPI\Microsoft.SharePoint.dll"       
[System.Reflection.Assembly]::LoadFile($file) | out-null

# Get Content Service of the farm
$contentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService

# Display and change the setting of property "CollectSPRequestAllocationCallStacks"
write-host "Current: " $contentService.CollectSPRequestAllocationCallStacks 

$contentService.CollectSPRequestAllocationCallStacks = $true
$contentService.Update()
write-host "    New: " $contentService.CollectSPRequestAllocationCallStacks 

the script works but doesnt change the message in the log.

On this page and elsewhere it suggests setting the following registry key (creating if necessary)

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\HeapSettings

New Dword Value = 1

This hasn't worked either.

I have used SPDisposeCheck and it doesnt return anything. I don't believe this link or this link provides any more information either.

My questions are

Is there anything else I can do to determine where the object was allocated?

If this message is shown to occur in Microsoft SharePoint code, what can I do to fix and what is the risk of doing nothing?

UPDATE
I noticed the error is also appearing when the list item is updated.

On Clicking Save in my custom web part this code is run..

        SPItem item = UpdateListItem();
        if (item != null)
        {
            Redirect(item.ID);
        }

UpdateListItem does the following

private SPListItem UpdateListItem()
{
    SPList list = SPContext.Current.Web.Lists[ListName];
    if (list != null)
    {
        SPListItem item = null;
        if (Item != null)
        {
            item = Item;

            item["EventReceiverInProcess"] = true;
            item.Update();

        }

        return item;
    }

    return null;
}

Item is a property..

protected override SPListItem Item
{
    get
    { 
        var result = (SPListItem)RequestIDField.Item;
        if (result != null && result.ID > 0)
        {
            return result;
        }
        else
        {
            return null;
        }
    }
}

The SPRequest object was not disposed error appears on completing the Redirect line, which basically redirects to the same page, but if I dont execute the line the error still appears.

I've commented out all code in my ItemUpdating(SPItemEventProperties properties) method.

The line that causes the error to appear is item.Update();

Update 2

I've found these two links which appear to be somewhat related to my issue

http://blog.furuknap.net/splist-rootfolder-causes-dispose-problem http://solutionizing.net/2009/01/09/splist-parentweb-leaks-revisited/

However updating the code to do the following hasn't worked

private SPListItem UpdateListItem()
{
    SPList list = SPContext.Current.Web.Lists[ListName];
    if (list != null)
    {
        SPListItem item = null;
        if (Item != null)
        {
            item = Item;

            item["EventReceiverInProcess"] = true;
            item.Update();

                if (item.Web != null)
                {
                    item.Web.Dispose();
                }

                if (item.ParentList.ParentWeb != null)
                {
                    item.ParentList.ParentWeb.Dispose();
                }

                if (item.ParentList.Lists.Web != null)
                {
                    item.ParentList.Lists.Web.Dispose();
                }

        }

        return item;
    }

    return null;
}

Update 3
For a bit more clarity in tracking this down, I have commented out the whole SPItemEventReceiver class on this list.

Not sure if relevant but as a bit of extra information this list has custom security applied, and it has a managed meta data column.

Update 4

After removing basically all my custom code and still getting the error, I went the other way and went with ootb functionality which still generates the error. (Updated to Service Pack 2)

  1. create new web application in central admin
  2. create new site collection based on team template in central admin
  3. in site collection add a site column of type managed meta data
  4. in site collection create a custom list
  5. Update the list settings, add the managed meta data site column
  6. Add new item on list - (see image)
  7. confirm error message in log
  8. edit list and remove the managed meta data site column
  9. add new item to list
  10. confirm error not in log

    adding item to list

This is basically exactly the same behaviour as seen here -

Memory leak in Microsoft.Sharepoint.Taxonomy.TaxonomyItemEventReceivers?

share|improve this question
    
Sadly, SharePoint is leaking even without any custom code, especially the 'upgrade look&feel to 2013'. Your code looks fine, the EventFiringEnabled changes only some flags inside thread as far as I remember. The UpdateValue<bool> is custom, what does it do? –  ppatalong Dec 12 '13 at 21:20
    
@ali Sharepoint - I've added the code example as requested –  Paul Rowland Dec 13 '13 at 5:35
2  
you dont need to call item.Web.Dispose(), item.ParentList.ParentWeb.Dispose() and item.ParentList.Lists.Web.Dispose() –  Remko Dec 13 '13 at 6:57
    
@Remko - that may well be true, especially as they didn't fix what I was trying to fix... (they are not in my initial UpdateListItem sample code) if you look at the two links immediately above at furuknap.net and solutionizing.net, they appear to try something similar. it still leaves me with an sprequest object not disposed error in the logs –  Paul Rowland Dec 13 '13 at 22:14

3 Answers 3

I can't see a place where you leave an open web opened - the risk is higher resource usage for a longer time, if you dispose properly you would need less resources.

If this event receiver is not used frequently, I would ignore it.

share|improve this answer
2  
unfortunately it is a core piece of 'my' solution.... but what would you call 'frequently'... 100 times per day? 100 times per hour? –  Paul Rowland Dec 10 '13 at 23:43
    
I'd define it as at least 1 per sec - otherwise it wont kill your farm. –  Max Melcher Dec 11 '13 at 6:25
    
+1 on would ignore it. 100 times per day is frequent, but it should not be a huge issue. 100 times per hour would be bottleneck. –  ppatalong Dec 12 '13 at 21:30
1  
"Max Melcher" says 3600 per hour would be the threshold and @ppatalong says 100 per hour would be the threshold... My estimate is it will probably occur something a little above 100 per hour.... –  Paul Rowland Dec 13 '13 at 5:34
    
There is not threshold - thats just how I define high frequency... –  Max Melcher Dec 13 '13 at 8:32

Can you show some code in what your doing in your list event? Somewhere you're not disposing of the spweb or spsite object.

Just like when you use itemUpdating event and then you update the list it would run into an endless loop, adding this.EventFiringEnabled = false; would solve it. In your case I need to see code to know exactly what is causing it to show that error. There is a leak somwhere within the event reciver.

So your looping once and the object is disposed and then it loops again with the same spweb / spsite object but it fails becasue the object doesnt exist. this.EventFiringEnabled = false; forces no method to run before you update, so you update first and then what ever other function is going to run does run.

http://www.sharepointassist.com/2009/11/19/error-request-not-found-in-the-trackedrequests/

share|improve this answer
    
Which code do you want to see? The ItemAdded event code is complete up to the point the error appears in the log... Are you suggesting its possible SPDisposeCheck doesnt find instances of not disposing spweb/spsite object? –  Paul Rowland Dec 10 '13 at 23:26
1  
SPDisposeCheck is not 100% perfect. –  Max Melcher Dec 11 '13 at 6:24
    
@PaulRowland yes SPDisposeCheck is not perfect ;) it does miss out from time to time hence why i asked for the code to make sure its correct just incase :) –  ali Sharepoint Dec 11 '13 at 8:34

I see the real problem now: You recurse with your item.update() call. The memory leak could occur when SharePoint stops this recursion.

You should prevent recursion with this: this.EventFiringEnabled = false;

And enable it afterwards: this.EventFiringEnabled = true;

See this blog post: http://www.mattjimison.com/blog/2011/05/11/disable-event-receivers-during-an-update/

Additionally: Dont dispose the properties.Web - its taken care of automatically: http://blogs.technet.com/b/stefan_gossner/archive/2008/12/05/disposing-spweb-and-spsite-objects.aspx

share|improve this answer
    
Do you mean in the SPItemEventReceiver class? I'm using ItemAdded and ItemUpdating in the eventreceiver class and was already setting EventFiringEnabled to false/true. For the purpose of tracking this down, I've commented out the whole class.... still getting the error in the log though. –  Paul Rowland Dec 16 '13 at 1:12
    
Actually yes. Try attach with a debugger and see if you recurse in the item updating event. –  Max Melcher Dec 16 '13 at 6:05
    
@Max.... there is no ItemUpdating event... I commented it out. When the class was there the EventFiringEnabled flag was already being set to false at the top and true at the bottom. Am I misunderstanding you? I've been commenting out whole sections of code in an effort to narrow down the issue. I appreciate your time on this, could you update your answer with an example. –  Paul Rowland Dec 16 '13 at 11:25
1  
I would start from zero then: Check if the event receiver is attached multiple times. If not, start with only adding and small portions of code until you get the same behavior - then post that code please. –  Max Melcher Dec 17 '13 at 7:02
    
started from zero and reproduced the log message with no custom code... –  Paul Rowland Dec 18 '13 at 23:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.