SharePoint SPRequest Leak

sharepointsharepoint-2010

I have been getting this weird message in the ULS ever since I ported the code over to SharePoint 2010.

Here is the message:

w3wp.exe (0x1320)
0x1168 SharePoint Foundation
General
90hv
Unexpected

Detected use of SPRequest for previously closed SPWeb object. Please close SPWeb objects when you are done with all objects obtained from them, but not before.

Stack trace:
at Microsoft.SharePoint.SPWorkItem.FetchData()
at Microsoft.SharePoint.SPWorkItem.retrieveSchema(Schema schemaIndex)
at Microsoft.SharePoint.SPWorkItem.get_SiteId()
at Microsoft.SharePoint.SPWorkItem.Delete()
at Microsoft.SharePoint.Workflow.SPWinOeHostServices.WorkItemDequeue(Transaction txn, Object[] transData)
at Microsoft.SharePoint.Workflow.SPPendingWorkBatch.Commit(Transaction transaction, ICollection items)
at System.Workflow.Runtime.WorkBatch.PendingWorkCollection.Commit(Transaction transaction)
at System.Workflow.Runtime.WorkBatch.Commit(Transaction transaction)
at System.Workflow.Runtime.Hosting.WorkflowCommitWorkBatchService.CommitWorkBatch(CommitWorkBatchCallback commitWorkBatchCallback)
at System.Workflow.Runtime.Hosting.DefaultWorkflowCommitWorkBatchService.CommitWorkBatch(CommitWorkBatchCallback commitWorkBatchCallback)
at System.Workflow.Runtime.WorkflowExecutor.CommitTransaction(Activity activityContext)
at System.Workflow.Runtime.WorkflowExecutor.Persist(Activity dynamicActivity, Boolean unlock, Boolean needsCompensation)
at System.Workflow.Runtime.WorkflowExecutor.System.Workflow.ComponentModel.IWorkflowCoreRuntime.PersistInstanceState(Activity activity)
at System.Workflow.ComponentModel.Activity.MarkClosed()
at System.Workflow.ComponentModel.Activity.ReleaseLockOnStatusChange(IActivityEventListener1 eventListener)
at System.Workflow.ComponentModel.FaultAndCancellationHandlingFilter.SafeReleaseLockOnStatusChange(ActivityExecutionContext context)
at System.Workflow.ComponentModel.FaultAndCancellationHandlingFilter.OnEvent(Object sender, ActivityExecutionStatusChangedEventArgs e)
at System.Workflow.ComponentModel.ActivityExecutorDelegateInfo
1.ActivityExecutorDelegateOperation.Run(IWorkflowCoreRuntime workflowCoreRuntime)
at System.Workflow.Runtime.Scheduler.Run()
at System.Workflow.Runtime.WorkflowExecutor.RunScheduler()
at System.Workflow.Runtime.WorkflowExecutor.RunSome(Object ignored)
at System.Workflow.Runtime.Hosting.DefaultWorkflowSchedulerService.WorkItem.Invoke(WorkflowSchedulerService service)
at System.Workflow.Runtime.Hosting.ManualWorkflowSchedulerService.RunOne(Guid workflowInstanceId)
at System.Workflow.Runtime.Hosting.ManualWorkflowSchedulerService.RunWorkflow(Guid workflowInstanceId)
at Microsoft.SharePoint.Workflow.SPWinOeHostServices.Send(SPWorkflow workflow, SPWinOeWorkflow winoeworkflow, SPWorkflowEvent e)
at Microsoft.SharePoint.Workflow.SPWinOeEngine.RunWorkflow(SPWorkflowHostService host, SPWorkflow workflow, Collection1 events, TimeSpan timeOut)
at Microsoft.SharePoint.Workflow.SPWorkflowManager.RunWorkflowElev(SPWorkflow workflow, Collection
1 events, SPWorkflowRunOptionsInternal runOptions)
at Microsoft.SharePoint.Workflow.SPWorkflowManager.StartWorkflowElev(Object context, SPWorkflowAssociation association, DateTime elevationTimeUtc, SPWorkflowEvent startEvent, SPWorkflowRunOptions runOptions)
at Microsoft.SharePoint.Workflow.SPWorkflowAutostartEventReceiver.<>c_DisplayClass1.b_0(SPSite superUserSite, SPWeb superUserWeb)
at Microsoft.SharePoint.SPSecurity.<>c_DisplayClassf.b_e()
at Microsoft.SharePoint.SPSecurity.<>c_DisplayClass4.b_2()
at Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated secureCode)
at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(WaitCallback secureCode, Object param)
at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(CodeToRunElevated secureCode)
at Microsoft.SharePoint.Workflow.SPWorkflowAutostartEventReceiver.AutoStartWorkflow(SPItemEventProperties properties, Boolean bCreate, Boolean bChange, AssocType atyp)
at Microsoft.SharePoint.Workflow.SPWorkflowAutostartEventReceiver.ItemUpdated(SPItemEventProperties properties)
at Microsoft.SharePoint.SPEventManager.RunItemEventReceiver(SPItemEventReceiver receiver, SPUserCodeInfo userCodeInfo, SPItemEventProperties properties, SPEventContext context, String receiverData)
at Microsoft.SharePoint.SPEventManager.RunItemEventReceiverHelper(Object receiver, SPUserCodeInfo userCodeInfo, Object properties, SPEventContext context, String receiverData)
at Microsoft.SharePoint.SPEventManager.<>c_DisplayClassc`1.b_6()
at Microsoft.SharePoint.SPSecurity.RunAsUser(SPUserToken userToken, Boolean bResetContext, WaitCallback code, Object param)
at Microsoft.SharePoint.SPEventManager.InvokeEventReceivers[ReceiverType](SPUserToken userToken, Guid tranLockerId, RunEventReceiver runEventReceiver, Object receivers, Object properties, Boolean checkCancel)
at Microsoft.SharePoint.SPEventManager.InvokeEventReceivers[ReceiverType](Byte[] userTokenBytes, Guid tranLockerId, RunEventReceiver runEventReceiver, Object receivers, Object properties, Boolean checkCancel)
at Microsoft.SharePoint.SPEventManager.HandleEventCallback[ReceiverType,PropertiesType](Object callbackData)
at Microsoft.SharePoint.Utilities.SPThreadPool.WaitCallbackWrapper(Object state)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.Run(ExecutionContextexecutionContext, ContextCallback callback, Object state)
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(_ThreadPoolWaitCallback tpWaitCallBack)
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(Object state)

This message comes up whenever I run the workflow, it does not appear to have any harmful effects to the workflow.

Please let me know anything you folks know.

Best Answer

Here's the guidance from MS around the proper disposal of SharePoint objects. Odds are good that if you're following all of these (correctly) then your code will be ok. The SPDisposeCheck tool can also be helpful, although in my exeprience you still need to know all of the disposal rules. This tool only does a static analysis and can return a lot of candidate issues that may actually be fine.

Related Topic