Enable CollectSPRequestAllocationCallStacks with PowerShell
· Ingo Karstein
I got this message in the ULS log:
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: {646667A7-73BC-4DDD-B0FB-6EDFC315CCE7} To determine where this object was allocated, set Microsoft.SharePoint.Administration.SPWebService.ContentService.CollectSPRequestAllocationCallStacks = true.
The following PowerShell script will do that for me – and you :-)
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
[System.Reflection.Assembly]::LoadFile($Env:CommonProgramFiles+"Microsoft SharedWeb Server Extensions14ISAPIMicrosoft.SharePoint.dll") | 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 3 comments
Steve Mushkat Jan 11, 2012
Helpful, thanks!
sp2007hut Jan 25, 2012
Awesome! Small suggestion:
if you replace
$contentService.CollectSPRequestAllocationCallStacks = $true
by
$contentService.CollectSPRequestAllocationCallStacks = -not $contentService.CollectSPRequestAllocationCallStacks
you can create a toggle script making it a solution that can set and unset as well.
Adam Mar 13, 2014
If you enable this and are still not seeing the callstacks does it mean there is nothing to show or is something else preventing the logging. Do you have to have a Verbose level of logging?