SPRequest ULS Entries

The SharePoint ULS logs always report objects not being explicitly disposed of, even for some of the SharePoint object model calls, although these are supposedly false positives.

Now, not all entries that are flagged will be issues, but initially there’s no apparent easy way of determining if the object is indeed causing a memory leak.

A sample log entry will look like:

An SPRequest object was reclaimed by the garbage collector instead of being explicitly freed. 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. Allocation Id: {FDE3179D-E9C7-476B-9E60-ED68C55827ED} To determine where this object was allocated, set Microsoft.SharePoint.Administration.SPWebService.ContentService. CollectSPRequestAllocationCallStacks = true.

The last line of this entry indicates a way of getting more useful information to allow you to diagnose the problem and determine if it requires fixing.

How can you set this property? The following PowerShell script will do the job for you:

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

Or, if you’re using SharePoint 2007, add the following DWORD key to the registry:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\HeapSettings\SPRequestStackTrace with the value 1

Now, you’ll notice the ULS logs will contain a lot more information for the SPRequest categories. For example:

An SPRequest object was reclaimed by the garbage collector instead of being explicitly freed. 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. Allocation Id: {1AAF2427-EC8E-4478-A2DB-612D2A01AEA6} This SPRequest was allocated
at
at Microsoft.SharePoint.Library.SPRequest..ctor()
at Microsoft.SharePoint.SPGlobal.CreateSPRequestAndSetIdentity(SPSite site, String name, Boolean bNotGlobalAdminCode, String strUrl, Boolean bNotAddToContext, Byte[] UserToken, String userName, Boolean bIgnoreTokenTimeout, Boolean bAsAnonymous)
at Microsoft.SharePoint.SPWeb.InitializeSPRequest()
at Microsoft.SharePoint.SPWeb.GetSiteData(SPSiteDataQuery query)
at CustomAssembly.SharePoint.CustomMethod(Guid listId)

On a side note, it’s worth mentioning that the SPLimitedWebPartManager and SPWorkflowManager SharePoint classes implement the IDisposable interface and therefore require explicit disposing within your code, something that tools like SPDisposeCheck do not detect.

This entry was posted in SharePoint and tagged , , . Bookmark the permalink.
0 0 votes
Article Rating
Subscribe
Notify of
guest

Solve the maths problem shown below before posting: *

0 Comments
Inline Feedbacks
View all comments