title: SharePoint SPRequest Leak
body: <p>I have been getting this weird message in the ULS ever since I ported the code over to SharePoint 2010.</p>
  
  <p>Here is the message:</p>
  
  <blockquote>
    <p>w3wp.exe (0x1320)<br>
    0x1168    SharePoint Foundation<br>
    General<br>
    90hv<br>
    Unexpected    </p>
    
    <p>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.</p>
    
    <p>Stack trace:<br>
      at Microsoft.SharePoint.SPWorkItem.FetchData()<br>
      at Microsoft.SharePoint.SPWorkItem.retrieveSchema(Schema schemaIndex)<br>
      at Microsoft.SharePoint.SPWorkItem.get_SiteId()<br>
      at Microsoft.SharePoint.SPWorkItem.Delete()<br>
      at Microsoft.SharePoint.Workflow.SPWinOeHostServices.WorkItemDequeue(Transaction txn, Object[] transData)<br>
      at Microsoft.SharePoint.Workflow.SPPendingWorkBatch.Commit(Transaction transaction, ICollection items)<br>
      at System.Workflow.Runtime.WorkBatch.PendingWorkCollection.Commit(Transaction transaction)<br>
      at System.Workflow.Runtime.WorkBatch.Commit(Transaction transaction)<br>
      at System.Workflow.Runtime.Hosting.WorkflowCommitWorkBatchService.CommitWorkBatch(CommitWorkBatchCallback commitWorkBatchCallback)<br>
      at System.Workflow.Runtime.Hosting.DefaultWorkflowCommitWorkBatchService.CommitWorkBatch(CommitWorkBatchCallback commitWorkBatchCallback)<br>
      at System.Workflow.Runtime.WorkflowExecutor.CommitTransaction(Activity activityContext)<br>
      at System.Workflow.Runtime.WorkflowExecutor.Persist(Activity dynamicActivity, Boolean unlock, Boolean needsCompensation)<br>
      at System.Workflow.Runtime.WorkflowExecutor.System.Workflow.ComponentModel.IWorkflowCoreRuntime.PersistInstanceState(Activity activity)<br>
      at System.Workflow.ComponentModel.Activity.MarkClosed()<br>
      at System.Workflow.ComponentModel.Activity.ReleaseLockOnStatusChange(IActivityEventListener<code>1 eventListener)<br>
      at System.Workflow.ComponentModel.FaultAndCancellationHandlingFilter.SafeReleaseLockOnStatusChange(ActivityExecutionContext context)<br>
      at System.Workflow.ComponentModel.FaultAndCancellationHandlingFilter.OnEvent(Object sender, ActivityExecutionStatusChangedEventArgs e)<br>
      at System.Workflow.ComponentModel.ActivityExecutorDelegateInfo</code>1.ActivityExecutorDelegateOperation.Run(IWorkflowCoreRuntime workflowCoreRuntime)<br>
      at System.Workflow.Runtime.Scheduler.Run()<br>
      at System.Workflow.Runtime.WorkflowExecutor.RunScheduler()<br>
      at System.Workflow.Runtime.WorkflowExecutor.RunSome(Object ignored)<br>
      at System.Workflow.Runtime.Hosting.DefaultWorkflowSchedulerService.WorkItem.Invoke(WorkflowSchedulerService service)<br>
      at System.Workflow.Runtime.Hosting.ManualWorkflowSchedulerService.RunOne(Guid workflowInstanceId)<br>
      at System.Workflow.Runtime.Hosting.ManualWorkflowSchedulerService.RunWorkflow(Guid workflowInstanceId)<br>
      at Microsoft.SharePoint.Workflow.SPWinOeHostServices.Send(SPWorkflow workflow, SPWinOeWorkflow winoeworkflow, SPWorkflowEvent e)<br>
      at Microsoft.SharePoint.Workflow.SPWinOeEngine.RunWorkflow(SPWorkflowHostService host, SPWorkflow workflow, Collection<code>1 events, TimeSpan timeOut)<br>
      at Microsoft.SharePoint.Workflow.SPWorkflowManager.RunWorkflowElev(SPWorkflow workflow, Collection</code>1 events, SPWorkflowRunOptionsInternal runOptions)<br>
      at Microsoft.SharePoint.Workflow.SPWorkflowManager.StartWorkflowElev(Object context, SPWorkflowAssociation association, DateTime elevationTimeUtc, SPWorkflowEvent startEvent, SPWorkflowRunOptions runOptions)<br>
      at Microsoft.SharePoint.Workflow.SPWorkflowAutostartEventReceiver.&lt;>c_<em>DisplayClass1.b</em>_0(SPSite superUserSite, SPWeb superUserWeb)<br>
      at Microsoft.SharePoint.SPSecurity.&lt;>c_<em>DisplayClassf.b</em>_e()<br>
      at Microsoft.SharePoint.SPSecurity.&lt;>c_<em>DisplayClass4.b</em>_2()<br>
      at Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated secureCode)<br>
      at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(WaitCallback secureCode, Object param)<br>
      at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(CodeToRunElevated secureCode)<br>
      at Microsoft.SharePoint.Workflow.SPWorkflowAutostartEventReceiver.AutoStartWorkflow(SPItemEventProperties properties, Boolean bCreate, Boolean bChange, AssocType atyp)<br>
      at Microsoft.SharePoint.Workflow.SPWorkflowAutostartEventReceiver.ItemUpdated(SPItemEventProperties properties)<br>
      at Microsoft.SharePoint.SPEventManager.RunItemEventReceiver(SPItemEventReceiver receiver, SPUserCodeInfo userCodeInfo, SPItemEventProperties properties, SPEventContext context, String receiverData)<br>
      at Microsoft.SharePoint.SPEventManager.RunItemEventReceiverHelper(Object receiver, SPUserCodeInfo userCodeInfo, Object properties, SPEventContext context, String receiverData)<br>
      at Microsoft.SharePoint.SPEventManager.&lt;>c_<em>DisplayClassc`1.b</em>_6()<br>
      at Microsoft.SharePoint.SPSecurity.RunAsUser(SPUserToken userToken, Boolean bResetContext, WaitCallback code, Object param)<br>
      at Microsoft.SharePoint.SPEventManager.InvokeEventReceivers[ReceiverType](SPUserToken userToken, Guid tranLockerId, RunEventReceiver runEventReceiver, Object receivers, Object properties, Boolean checkCancel)<br>
      at Microsoft.SharePoint.SPEventManager.InvokeEventReceivers[ReceiverType](Byte[] userTokenBytes, Guid tranLockerId, RunEventReceiver runEventReceiver, Object receivers, Object properties, Boolean checkCancel)<br>
      at Microsoft.SharePoint.SPEventManager.HandleEventCallback[ReceiverType,PropertiesType](Object callbackData)<br>
      at Microsoft.SharePoint.Utilities.SPThreadPool.WaitCallbackWrapper(Object state)<br>
      at System.Threading.ExecutionContext.runTryCode(Object userData)<br>
      at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)<br>
      at System.Threading.ExecutionContext.Run(ExecutionContextexecutionContext, ContextCallback callback, Object state)<br>
      at System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(_ThreadPoolWaitCallback tpWaitCallBack)<br>
      at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(Object state)   </p>
  </blockquote>
  
  <p>This message comes up whenever I run the workflow, it does not appear to have any harmful effects to the workflow.</p>
  
  <p>Please let me know anything you folks know.</p>