Memory leak when using Workflow 4.0 SqlWorkflowInstanceStore and PersistableIdleAction.Unload

Posted by Rohland on Stack Overflow See other posts from Stack Overflow or by Rohland
Published on 2010-04-29T09:05:48Z Indexed on 2010/04/29 10:07 UTC
Read the original article Hit count: 600

Hi,

This particular problem is driving me nuts. I wonder if anyone has experienced a similar problem. If I load up a workflow then unload it and perform a memory snapshot then the result is predictable - my workflow is no longer in memory. However, if I load up a workflow and set the PersistableIdle action to PersistableIdleAction.Unload and let the workflow idle the workflow remains in memory even though the Unload action fires.

I used ANTS Memory Profiler to debug this issue. This is the object retention graph outputted showing that an internal object is hanging onto my workflow instance.

alt text

Can anyone else verify this problem? My code amounts to the following:

  1. Create SqlWorkflowInstanceStore and setup lock owner handle
    -- At this point I take a memory snapshot
  2. Create an instance of Workflow1
  3. Set the PersistableIdle action
  4. Apply the instancestore to Workflow1
  5. Setup action event handlers for Idle, Unload, UnhandledException etc.
  6. Persist the workflow instance
  7. Run the workflow instance
  8. Wait for instance to idle (caused by Delay activity)
  9. Ensure the Unload action is fired
    -- At this point I take a second memory snapshot

From the above image, it is clear that the only object referencing Workflow1 is some internal event handlers result which I have no ability to dispose of.

Any clues?

© Stack Overflow or respective owner

Related posts about workflow-foundation-4

Related posts about Workflow