SharePoint How To:定位错误:“An SPRequest object was not disposed .."

我们的Sharepoint程序有时泄露了很多SPWeb,SPSite对象,SharePoint日志中就会有很多错误信息,如下:

   

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: {5E41622E-AFA6-44E4-AAB3-809A70D39CCA} To determine where this object was allocated, set Microsoft.SharePoint.Administration.SPWebService.ContentService.CollectSPRequestAllocationCallStacks = true(线索).

   

如果您细心地话,您会发现上面日志中提到了一个参数,按照要求设置后就可以看到完整的CallStacks

   

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: {A635DEED-3786-40C7-BA42-6D3E3CB4571B} 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.SPFieldCollection.EnsureFieldsSafeArray(Boolean bGetFullXML)

at Microsoft.SharePoint.SPFieldCollection.get_DisplayNameDict()

at Microsoft.SharePoint.SPFieldCollection.GetFieldByDisplayName(String strDisplayName, Boolean bThrowException)

at SharePointBoost.Workflow.Common.WorkflowRepository.GetItems(SPList list, Hashtable condition)

at SharePointBoost.Workflow.Common.WorkflowRepository.GetWorkflow(String workflowId, VersionType version)

at SharePointBoost.Workflow.Layouts.ApplicationPages.WorkflowDesigner.CreateWorkflowDesigner(String workflowID, VersionType version)

at SharePointBoost.Workflow.Layouts.ApplicationPages.WorkflowDesigner.Page_Load(Object sender, EventArgs e)

at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)

at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)

at System.Web.UI.Control.OnLoad(EventArgs e)

at Microsoft.SharePoint.WebControls.UnsecuredLayoutsPageBase.OnLoad(EventArgs e)

at Microsoft.SharePoint.WebControls.LayoutsPageBase.OnLoad(EventArgs e)

at System.Web.UI.Control.LoadRecursive()

at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

at System.Web.UI.Page.ProcessRequest()

at System.Web.UI.Page.ProcessRequest(HttpContext context)

at ASP._layouts_sharepointboost_workflow_workflowdesigner_aspx.ProcessRequest(HttpContext context)

at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()

at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

at System.Web.HttpApplication.PipelineStepManager.ResumeSteps(Exception error)

at System.Web.HttpApplication.BeginProcessRequestNotification(HttpContext context, AsyncCallback cb)

at System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context)

at System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr managedHttpContext, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)

at System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr managedHttpContext, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)

at System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr managedHttpContext, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)

at System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr managedHttpContext, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)

   

运行下面的的Power Shell代码设置Microsoft.SharePoint.Administration.SPWebService.ContentService.CollectSPRequestAllocationCallStacks。(如果没用过Power Shell,参考:http://technet.microsoft.com/en-us/library/ee176949.aspx 

 

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

[System.Reflection.Assembly]::LoadFile($Env:CommonProgramFiles+"\Microsoft Shared\Web Server Extensions\14\ISAPI\Microsoft.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

   

   

   

   

   

posted @ 2011-10-24 10:30  心利  阅读(578)  评论(0编辑  收藏  举报
SharePoint Add-ons