locked
Workflow Designer 4.0 Load() Performance Issue: possible memory leak? RRS feed

  • General discussion

  • Hello everybody,

    I am trying to implement a workflow designer in a windows form application and use the same designer to view different workflows. However, I found the program became slower and slower after loading several workflows.

    my steps are as follows:

    1. create a wpf user control WFDesigner to package the workflowdesigner;

    2. In the user control  WFDesigner , implement a InitiateDesigner method which create a new workflowDesigner instance each time called. I suppose the old workflowDesigner instance would be collected by GC;

    3. create a winform application and install the user control created on step 2 to an element host, and put the element host on the form. 

    4. add two buttons for test: one will execute  WFDesigner.InitiateDesigner() once and the other will execute it 100 times. 

    The result: I found to execute the function  WFDesigner.InitiateDesigner() in the beginning it took about 140ms, after executing 100 times it took 800 ms and after 200 times it took 1600 ms. The memory consumption goes high as well : in the beginning it's around 50Mb, then it's 120Mb after 100 times' execution and 180 Mb after 200 times.

    below is my code for WPF control WFDesigner

      public partial class WFDesigner : UserControl
      {
        WorkflowDesigner workflowDesigner;
    
        public WorkflowDesigner WorkflowDesigner
        {
          get { return workflowDesigner; }
        }
    
        public WFDesigner()
        {
          InitializeComponent();
          InitiateDesigner(null);
        }
    
        public void InitiateDesigner(string text)
        {
          string designerText = text;
          //Create an instance of WorkflowDesigner class
          this.workflowDesigner = new WorkflowDesigner();
    
          // Flush the workflow when the model changes
          workflowDesigner.ModelChanged += (s, e) =>
          {
            workflowDesigner.Flush();
          };
    
          if (designerText == "" || designerText == null)
          {
            //Load a new Sequence as default.
            this.workflowDesigner.Load(new Sequence());
          }
          else
          {
            this.workflowDesigner.Text = designerText;
            this.workflowDesigner.Load();
          }
    
          //Add the WorkflowDesigner to the grid
          grid1.Children.Clear();
          grid1.Children.Add(this.workflowDesigner.View);
    
        }

    and the code for two buttons:

     

        private void btnSingleLoad_Click(object sender, EventArgs e)
        {
          DateTime before = DateTime.Now;
          ctrl.InitiateDesigner(null);
          
          DateTime after = DateTime.Now;
          TimeSpan ts = after - before;
          execTimeLabel.Text = "Load time: " + (ts.Seconds* 1000 + ts.Milliseconds).ToString() + " milliseconds";
        }
    
        private void btnMassLoad_Click(object sender, EventArgs e)
        {
          for (int i = 0; i < 100; i++)
            ctrl.InitiateDesigner(null);
        }
    

     

     

    • Changed type Andrew_Zhu Monday, May 10, 2010 9:07 AM known issue
    Monday, May 3, 2010 11:05 AM

All replies

  • thanks for your reporting.

    this is a known issue, we are looking at it.

    Monday, May 3, 2010 6:14 PM
  • Hi There,

    I'm experiencing the same problem, has there been any progress on this front yet?

    Thanks,

    Rob

    Friday, July 2, 2010 9:05 AM
  • One way to work around this issue is to host the workflow designer in a separate app domain and unload the app domain when it’s not used.

    I have a small prototype showing how to do it using MAF. Please contact me if you need the code, thus I could email it to you.

    Thanks,

    Tony (tonytang@microsoft.com)

    Thursday, July 8, 2010 2:12 AM
  • Hi,

    I am Alex from Autodesk. We are making a product using WF4 and have the same issue. Due to this issue, our product will crash after wf designer loads workflow several times. The workaround of AppDomain does not work in my case because there is a barrier between two app domains which blocks workflow designer app domain access document owned by default app domain.

    Best regards,

    Alex

    Friday, July 16, 2010 6:00 AM
  • Is there a fix for this yet?  Maybe a patch?
    Jason Bolstad
    Thursday, October 21, 2010 1:16 AM
  • How about a work around?
    Jason Bolstad
    Wednesday, October 27, 2010 7:57 PM
  • Hello all,

    You can check the status of the issue on connect here

    https://connect.microsoft.com/wf/feedback/details/575613/wf4-designer-causes-memory-leak

    Tim

    Monday, November 1, 2010 6:06 PM
  • Thanks for the pointer Tim. However that issue (https://connect.microsoft.com/wf/feedback/details/575613/wf4-designer-causes-memory-leak ) was closed in July. Any progress more recently?

    Thanks

    George

    Wednesday, November 3, 2010 10:37 AM
  • If more people can add comments to the issue saying they really want a fix, I should be able to get someone to reactivate it.
    Tim

    Wednesday, November 3, 2010 5:33 PM
  • I really want a fix!
    Jason Bolstad
    Sunday, November 7, 2010 8:35 PM
  • Please fix this, after a while the designer gets pretty slow!
    Greg
    Sunday, November 7, 2010 8:41 PM
  • Agreed! I also really want a fix!
    Monday, November 8, 2010 4:59 AM
  • This is a WPF bug rather than a workflow designer specific issue. We've contacted the WPF team and have been working with them to come up with a fix. The current plan is to include this fix in our next major release (not SP1). Right now, the workaround is to host every single workflow designer instance in a separate AppDomain.

    Thanks.

    Guang Yang

    Program Manager, Guang.Yang@microsoft.com

    Tuesday, November 9, 2010 9:36 PM
  • Hi Tony,

    I have Rehosted my WF Designer and I am also facing the same problem.

    Please email me on robin1.r@tcs.com

     

    Thanks & Regards,

    Robin Raina

    Wednesday, October 12, 2011 9:23 AM