How to know where you have a memory leak?

Posted on Updated on

All Sharepoint developers have seen sometimes this:

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.

And normally if you are a good one, you know how to fix it in the code you developed.   But, what about if you did not develop the code and you are trying to troubleshoot performance problems and memory leak. By default the ULS Logs only shows the page, but it wont show the methods, of the page that have the memory leak.   You can activate this with the following script.

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

Leave a comment