locked
Clearing Heap to solve a memory leak that occured because of an event receiver RRS feed

  • Question

  • Hi,

    I'm having a problem with memory where I have a workflow developed using SPD that has collect data from user action and sends some emails. I also have an event receiver on the task list associated with WF with type itemupdating to prevent user from editing a completed task. I'm still testing the solution and I want to make it available for users for production and everything was working well But I suddenly got an error where after the task is assigned in WF and the user completes it, it is still not started and when I try to edit it again I get "This task is currently locked by a running workflow and cannot be edited". I looked in the log files and found the below text

     

    09/14/2011 11:14:23.44  w3wp.exe (0x34DC)          0x2F2C Windows SharePoint Services General        8m90 Medium               39 heaps created, above warning threshold of 32. Check for excessive SPWeb or SPSite usage. 
    09/14/2011 11:14:23.47  w3wp.exe (0x34DC)            0x2F2C Windows SharePoint Services    General                        0 Monitorable Potentially excessive number of SPRequest objects (28) currently unreleased on thread 9.  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. Allocation Id for this object: {06CBB922-720E-4FEC-97C8-D793C5CC828B} Stack trace of current allocation:    at Microsoft.SharePoint.SPRequestManager.Add(SPRequest request, Boolean shareable)     at Microsoft.SharePoint.SPGlobal.CreateSPRequestAndSetIdentity(Boolean bNotGlobalAdminCode, String strUrl, Boolean bNotAddToContext, Byte[] UserToken, String userName, Boolean bIgnoreTokenTimeout, Boolean bAsAnonymous)     at Microsoft.SharePoint.SPWeb.InitializeSPRequest()     at Microsoft.SharePoint.SPWeb.EnsureSPRequest()     at Microsoft.SharePoint.SPWeb.get_Re... 
    09/14/2011 11:14:23.47* w3wp.exe (0x34DC)                        0x2F2C Windows SharePoint Services    General                        0 Monitorable ...quest()     at Microsoft.SharePoint.SPWeb.InitWeb()     at Microsoft.SharePoint.SPWeb.get_SecurableObjectImpl()     at Microsoft.SharePoint.SPWeb.get_HasUniqueRoleAssignments()     at Microsoft.SharePoint.SPUserCollection.UpdateMembers(Object objUpdateInfo, Object objRemoveLogins, Object objRemoveIds, Boolean fSendEmail)     at Microsoft.SharePoint.SPUserCollection.AddCollection(SPUserInfo[] addUsersInfo)     at Microsoft.SharePoint.SPUserCollection.Add(String loginName, String email, String name, String notes)     at Microsoft.SharePoint.WorkflowActions.Helper.ResolveToUserName(WorkflowContext context, String emailAddress)     at Microsoft.SharePoint.WorkflowActions.CollectDataTask.CreateAssignmentInfo()     at Microsoft.SharePoint.WorkflowActions.CollectDataTask.CreateInProperties(Object... 
    09/14/2011 11:14:23.47* w3wp.exe (0x34DC)                        0x2F2C Windows SharePoint Services    General                        0 Monitorable ... sender, EventArgs e)     at System.Workflow.ComponentModel.Activity.RaiseEvent(DependencyProperty dependencyEvent, Object sender, EventArgs e)     at System.Workflow.Activities.CallExternalMethodActivity.Execute(ActivityExecutionContext executionContext)     at System.Workflow.ComponentModel.ActivityExecutor`1.Execute(T activity, ActivityExecutionContext executionContext)     at System.Workflow.ComponentModel.ActivityExecutor`1.Execute(Activity activity, ActivityExecutionContext executionContext)     at System.Workflow.ComponentModel.ActivityExecutorOperation.Run(IWorkflowCoreRuntime workflowCoreRuntime)     at System.Workflow.Runtime.Scheduler.Run()     at System.Workflow.Runtime.WorkflowExecutor.RunScheduler()     at System.Workflow.Runtime.WorkflowExecutor.RunSome(Object ignored)     a... 
    09/14/2011 11:14:23.47* w3wp.exe (0x34DC)                        0x2F2C Windows SharePoint Services    General                        0 Monitorable ...t System.Workflow.Runtime.Hosting.DefaultWorkflowSchedulerService.WorkItem.Invoke(WorkflowSchedulerService service)     at System.Workflow.Runtime.Hosting.DefaultWorkflowSchedulerService.QueueWorkerProcess(Object state)     at System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(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.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)     at System.Threading._ThreadPoolWa... 
    09/14/2011 11:14:23.47* w3wp.exe (0x34DC)                        0x2F2C Windows SharePoint Services    General                        0 Monitorable ...itCallback.PerformWaitCallbackInternal(_ThreadPoolWaitCallback tpWaitCallBack)     at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(Object state)   
    09/14/2011 11:14:24.08  w3wp.exe (0x34DC)                        0x2F2C Windows SharePoint Services    General                        8l1o Verbose  SPSite should not be used with mixed impersonation state. If you do want to cache an SPSite created within RunWithElevatedPrivileges, call SPSite.BypassImpersonationStateCheck 
    09/14/2011 11:14:24.08  w3wp.exe (0x34DC)                        0x2F2C Windows SharePoint Services    General                        8l1o Verbose  SPSite should not be used with mixed impersonation state. If you do want to cache an SPSite created within RunWithElevatedPrivileges, call SPSite.BypassImpersonationStateCheck 
    09/14/2011 11:14:24.08  w3wp.exe (0x34DC)                        0x2F2C Windows SharePoint Services    General                        6t8h Verbose  Found typical site / (be85b6c0-0c7f-494c-836e-921ff288237c) in web application SPWebApplication Name=SharePoint - 80 Parent=SPWebService. 
    09/14/2011 11:14:24.10  w3wp.exe (0x34DC)                        0x2F2C Windows SharePoint Services    General                        8m90 Medium   40 heaps created, above warning threshold of 32. Check for excessive SPWeb or SPSite usage. 
    09/14/2011 11:14:24.11  w3wp.exe (0x34DC)                        0x2F2C Windows SharePoint Services    General                        0 Monitorable Potentially excessive number of SPRequest objects (29) currently unreleased on thread 9.  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. Allocation Id for this object: {22E0B033-B05E-49FD-8B1E-1AC414E2D536} Stack trace of current allocation:    at Microsoft.SharePoint.SPRequestManager.Add(SPRequest request, Boolean shareable)     at Microsoft.SharePoint.SPGlobal.CreateSPRequestAndSetIdentity(Boolean bNotGlobalAdminCode, String strUrl, Boolean bNotAddToContext, Byte[] UserToken, String userName, Boolean bIgnoreTokenTimeout, Boolean bAsAnonymous)     at Microsoft.SharePoint.SPWeb.InitializeSPRequest()     at Microsoft.SharePoint.SPWeb.EnsureSPRequest()     at Microsoft.SharePoint.SPWeb.get_Re... 
    09/14/2011 11:14:24.11* w3wp.exe (0x34DC)                        0x2F2C Windows SharePoint Services    General                        0 Monitorable ...quest()     at Microsoft.SharePoint.SPListCollection.EnsureListsData(Guid webId, String strListName)     at Microsoft.SharePoint.SPListCollection.EnsureListsData(String strListName)     at Microsoft.SharePoint.SPListCollection.ItemByInternalName(String strInternalName, Boolean bThrowException)     at Microsoft.SharePoint.SPListCollection.GetListById(Guid uniqueID, Boolean bThrowException)     at Microsoft.SharePoint.SPListCollection.get_Item(Guid uniqueID)     at Microsoft.SharePoint.Utilities.SPUtility.GetPermissions(SPUserToken token, ISecurableObject securableObject)     at Microsoft.SharePoint.Utilities.SPUtility.DoesUserHavePermissions(SPUser user, SPBasePermissions permissionMask, ISecurableObject securableObject)     at Microsoft.SharePoint.Workflow.WorkflowTaskUpdateMailUtil.StrIte... 
    09/14/2011 11:14:24.11* w3wp.exe (0x34DC)                        0x2F2C Windows SharePoint Services    General                        0 Monitorable ...mLink()     at Microsoft.SharePoint.Workflow.WorkflowTaskUpdateMailUtil.StrInstructionReview()     at Microsoft.SharePoint.Workflow.WorkflowTaskUpdateMailUtil.StrTaskInstructionsCommon(Boolean fDownLevel)     at Microsoft.SharePoint.Workflow.WorkflowTaskUpdateMailUtil.StrRow3(Boolean fOffsite)     at Microsoft.SharePoint.Workflow.WorkflowTaskUpdateMailUtil.GenerateEmailBody()     at Microsoft.SharePoint.Workflow.WorkflowTaskUpdateMailUtil.GenerateEmailBodyForNewTask(SPListItem item, SPUser author)     at Microsoft.SharePoint.Workflow.SPWinOETaskService.UpdateTaskInternal(Guid taskId, SPWorkflowTaskProperties properties, Boolean fSetWorkflowFinalize, Boolean fCreating, HybridDictionary specialPermissions)     at Microsoft.SharePoint.Workflow.SPWinOETaskService.CreateTaskWithContentTypeInter... 
    09/14/2011 11:14:24.11* w3wp.exe (0x34DC)                        0x2F2C Windows SharePoint Services    General                        0 Monitorable ...nal(Guid taskId, SPWorkflowTaskProperties properties, Boolean useDefaultContentType, SPContentTypeId ctid, HybridDictionary specialPermissions)     at Microsoft.SharePoint.Workflow.SPWinOETaskService.CreateTaskWithContentType(Guid taskId, SPWorkflowTaskProperties properties, String taskContentTypeId, HybridDictionary specialPermissions)     at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)     at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)     at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, ... 
    09/14/2011 11:14:24.11* w3wp.exe (0x34DC)                        0x2F2C Windows SharePoint Services    General                        0 Monitorable ...CultureInfo culture, Boolean skipVisibilityChecks)     at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)     at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)     at System.Workflow.Activities.CallExternalMethodActivity.Execute(ActivityExecutionContext executionContext)     at System.Workflow.ComponentModel.ActivityExecutor`1.Execute(T activity, ActivityExecutionContext executionContext)     at System.Workflow.ComponentModel.ActivityExecutor`1.Execute(Activity activity, ActivityExecutionContext executionContext)     at System.Workflow.ComponentModel.Ac... 
    09/14/2011 11:14:24.11* w3wp.exe (0x34DC)                        0x2F2C Windows SharePoint Services    General                        0 Monitorable ...tivityExecutorOperation.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.DefaultWorkflowSchedulerService.QueueWorkerProcess(Object state)     at System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(Object state)     at System.Threading.ExecutionContext.runTryCode(Object userData)     at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)     at System.Threading.Exec... 
    09/14/2011 11:14:24.11* w3wp.exe (0x34DC)                        0x2F2C Windows SharePoint Services    General                        0 Monitorable ...utionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)     at System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(_ThreadPoolWaitCallback tpWaitCallBack)     at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(Object state)   

     

    I checked my code for the event handler and recognized that I forgot to dispose items and I thought that this may be the cause of the problem, I corrected the code but I want to know how to clear the heap now and If I did so will the task be unlocked or I will have to restart the WF again.

    Thanks

    • Moved by Mike Walsh FIN Wednesday, September 14, 2011 12:03 PM Not general. Trying workflow (From:SharePoint - General Question and Answers and Discussion (pre-SharePoint 2010))
    Wednesday, September 14, 2011 11:45 AM

All replies

  • Hello,

    To assist in identifying the issues in the code, you can use SPDisposeCheck, which can be downloaded below:

    There is also a rule set for this tool that may assist you:

    You can refer the below articles too:

    After the code has been cleaned up, and no more memory leaks are showing up in the log files, you can run an iisreset to release the memory that is currently allocated unreleased objects.


    Please remember to click 'Mark as Answer' on the post that helps you or click 'Unmark as Answer' if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    Regards,
    Nishant Shah
    Microsoft Online Community Support
    • Edited by Nishant - MSFT Wednesday, September 21, 2011 11:12 AM
    • Marked as answer by Wayne Fan Saturday, September 24, 2011 6:28 AM
    • Unmarked as answer by Marwa Mostafa Saturday, September 24, 2011 9:20 AM
    • Proposed as answer by Reach Ram Monday, February 24, 2014 1:26 PM
    Wednesday, September 21, 2011 11:11 AM
  • Hi,

    I actually installed this tool but there was no problem, I noticed that the problem occurs on just accessing a certain site which means that it isn't related to the code and when I searched the internet, I found the below article:

    http://blogs.technet.com/b/stefan_gossner/archive/2008/05/07/troubleshooting-spsite-spweb-leaks-in-wss-v3-and-moss-2007.aspx

    this article mentioned that the error may happen according to the design of site and that I can set a key in registry to solve this issue

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\HeapSettings

            LocalSPRequestWarnCount = 50

    I did so and restarted the server but I still got the same warning and the message is :

    Potentially excessive number of SPRequest objects (9) currently unreleased on thread 12.

    I don't know why it appears although I set the value to 50 and value here is just 9.

    I tried to access another site that is at the same level but I didn't get this warning so I want to know what may cause this warning with this site.

    Thanks in advance

    Saturday, September 24, 2011 9:34 AM
  • Hello,

    The same article you found is mentioned in my post above. 9 is not a concerning number however there are still some objects which are not correctly disposed. If this number is still a concern, please check for any custom solutions which may not be disposing objects correctly.


    Please remember to click 'Mark as Answer' on the post that helps you or click 'Unmark as Answer' if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    Regards,
    Nishant Shah
    Microsoft Online Community Support
    Monday, September 26, 2011 9:02 AM