An SPRequest object was not disposed before the end of this thread :SharePoint

I had a problem this morning – Not able to access SharePoint site. When I start debugging with ULS, I see below errors all over the place.

Problem:


—————————————————————————————————————
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: {GUID} To determine where this object was allocated, set Microsoft.SharePoint.Administration.SPWebService.ContentService.CollectSPRequestAllocationCallStacks = true.
—————————————————————————————————————
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at Microsoft.SharePoint.Portal.WebControls.LocStringIdLookupTable..cctor()
—————————————————————————————————————

Finding a way to resolve the issue:


If the sites are not working at this point of time, try doing App pool recycle or IIS reset(not recommended in peak hours as it recycles all App pools leading temporary outage).

To simply enable the stack trace below powershell can be used.

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$contentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$contentService.CollectSPRequestAllocationCallStacks = $true
$contentService.Update()

But, Microsoft suggested best practices should be used to dispose SPWeb and SPSite objects[Any SPRequests]. Most of the time these kind of issues could be because of Custom development.

To find out Any Dispose objects in your dll/exe file use SPDisposeCheck tool.

However installing SPDisposecheck tool is an add-on that can save your time and analyze your Visual Studio Code for non – disposed objects before code is deployed.

Here is a nice article – how to integrate SpDisposeCheck tool

Leave a comment