This post is about simple thing in SharePoint 2010 like string localization :) I know that method SPUtility.GetLocalizedString is well known for every SharePoint developer, but let's deep into details.

Potentially excessive number of SPRequest objects (16) currently unreleased on thread 41. Ensure that this object or its parent (such as an SPWeb or SPSite) is being properly disposed. This object is holding on to a separate native heap.This object will not be automatically disposed. Allocation Id for this object: {A19A2B81-8D0A-4A56-BE7C-1D816185417C} Stack trace of current allocation:
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.SPRequestManager.GetContextRequest(SPRequestAuthenticationMode authenticationMode)
at Microsoft.SharePoint.Administration.SPFarm.get_RequestAny()
What's wrong with this method?
Every call of this method will create SPRequest instance when HttpContext.Current is null. For example, if you have some timer job processes quite big amount of data and you have to save some localized strings (for example Choice field values), the system will create huge number of SPRequests. Of course these SPRequests are disposed by this method but anyway why do we need that if we already have instance of opened SPWeb that holds needed SPRequest instance?
Why it's wrong?
This is defenetly not critical problem but some customers worry about messages in ULS log like:Potentially excessive number of SPRequest objects (16) currently unreleased on thread 41. Ensure that this object or its parent (such as an SPWeb or SPSite) is being properly disposed. This object is holding on to a separate native heap.This object will not be automatically disposed. Allocation Id for this object: {A19A2B81-8D0A-4A56-BE7C-1D816185417C} Stack trace of current allocation:
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.SPRequestManager.GetContextRequest(SPRequestAuthenticationMode authenticationMode)
at Microsoft.SharePoint.Administration.SPFarm.get_RequestAny()
of course such messages could be caused by big amount of opened SPSites or SPWebs and actually such messages are reason for code review.
How to eliminate this in SharePoint 2010?
"Hack" is obvious - create fake HttpContext and set already created SPWeb to HttpContext.Current.Items["HttpHandlerSPWeb"]
But first of all - review the code and try to reduce number of opened SPSite, SPWeb objects at same time.
What about SharePoint 2013?
SharePoint 2013 has smarter implementation of Request
Комментариев нет:
Отправить комментарий