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)
- create new web application in central admin
- create new site collection based on team template in central admin
- in site collection add a site column of type managed meta data
- in site collection create a custom list
- Update the list settings, add the managed meta data site column
- Add new item on list - (see image)
- confirm error message in log
- edit list and remove the managed meta data site column
- add new item to list
confirm error not in log
This is basically exactly the same behaviour as seen here -
Memory leak in Microsoft.Sharepoint.Taxonomy.TaxonomyItemEventReceivers?