Search

Workflow Designer 4.0 Performance Issue: possible memory leak by Nestoyanov Vladimir

Closed
as Accepted Help for as Accepted

1
0
Sign in
to vote
Type: Bug
ID: 777780
Opened: 1/29/2013 9:19:14 AM
Access Restriction: Public
0
Workaround(s)
0
User(s) can reproduce this bug
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 to package the workflowdesigner.

2. In the user control, create a new workflowDesigner instance each time when called. I suppose the old workflowDesigner instance would be collected by GC.

3. Create a Winform control and install the WPF user control created on step 2 into an element host, and put the element host on the winform userControl.

4. Load Winform user control created in stpe 3 into a Tab inside a Winform application.

5. Using a button to launch and close the tab.

The result: First time when I launch the tab it consumes around 30MB of space (may be due to first time WPF assembly load), from next time onwards it takes 13MB in each launch and after 30-40 launch attempts memory consumption become large enough to me make application too slow.

I am disposing following objects explicitly:
Tab.
Element host.

Code:
private void InitializeWorkflowDesigner()
        {
            workflowDesigner = new WorkflowDesigner();
            workflowDesigner.Context.Items.GetValue<ReadOnlyState>().IsReadOnly = true;
            workflowDesigner.View.PreviewMouseDown += OnPreviewMouseDown;
            attachPropertyRecord = new AttachedProperty<ActivityStateRecord>
            {
                Name = "Record",
                Setter = (modelItem, tracingRecord) => modelItemMapping.SetRecordValue(modelItem, tracingRecord), // modelItemMapping is a class which provide mappings.
                Getter = modelItem => modelItemMapping.GetRecordValue(modelItem),
                OwnerType = typeof(Activity)
            };
            workflowDesigner.Context.Services.GetService<AttachedPropertiesService>().AddProperty(attachPropertyRecord);
            workflowDesigner.Load(workflowFilePath);
            grid.Children.Add(workflowDesigner.View); // grid is Grid of WPF control.

            var modelService = workflowDesigner.Context.Services.GetService<ModelService>();
            sourceLocationProvider = new SourceLocationProvider(
                                         workflowFilePath,
                                         modelService,
                                         workflowDesigner.Context.Items.GetValue<WorkflowFileItem>().LoadedFile,
                                         workflowDesigner.DebugManagerView);
            
            workflowDesigner.Context.Items.Subscribe<Selection>(OnSelectCallback);
            var designerView = workflowDesigner.Context.Services.GetService<DesignerView>();
            if (designerView != null)
            {
                designerView.WorkflowShellBarItemVisibility = // ShellBarItemVisibility.Imports |
                    ShellBarItemVisibility.MiniMap | // ShellBarItemVisibility.Variables |
                    // ShellBarItemVisibility.Arguments | <-- Uncomment to show again
                    ShellBarItemVisibility.Zoom;
            }
        }

/// Method which we call inside "SourceLocationProvider" constructor.
        private void UpdateSourceLocationMappingInDebuggerService(string workflowFilePath, DebuggerService debuggerService, string loadedFile, object rootInstance)
        {
            workflowElementToSourceLocationMap = new Dictionary<object, SourceLocation>();
            designerSourceLocationMapping = new Dictionary<object, SourceLocation>();

            if (rootInstance != null)
            {
                Activity documentRootElement = GetRootWorkflowElement(rootInstance);

                System.Activities.Debugger.SourceLocationProvider.CollectMapping(
                    GetRootRuntimeWorkflowElement(workflowFilePath),
                    documentRootElement,
                    workflowElementToSourceLocationMap,
                    loadedFile);

                // Collect the mapping between the Model Item tree and its underlying source location
                System.Activities.Debugger.SourceLocationProvider.CollectMapping(
                    documentRootElement,
                    documentRootElement,
                    designerSourceLocationMapping,
                    loadedFile);
            }

            // Notify the DebuggerService of the new sourceLocationMapping.
            // When rootInstance == null, it'll just reset the mapping.
            // DebuggerService debuggerService = debuggerService as DebuggerService;
            if (debuggerService != null)
            {
                debuggerService.UpdateSourceLocations(workflowElementToSourceLocationMap);
            }
        }
Details (expand)

Visual Studio/Team Foundation Server/.NET Framework Tooling Version

.NET Framework 4.0

Steps to reproduce

see description

Product Language

English

Operating System

Windows 7

Operating System Language

English

Actual results

see description

Expected results

see description
File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 3/27/2013 at 2:29 PM
Following the steps that you have mentioned here, we couldn't find any WF Designer leaks.

Please provide a repro project and more detailed repro steps if the problem persists.
Posted by Microsoft on 2/19/2013 at 11:31 AM
Thank you for your feedback.

We are looking into this issue. But for our investigation, we would need more details than what has already been mentioned in the bug.

Could you please attach a repro project to the bug?

We appreciate your help.
Posted by Microsoft on 1/29/2013 at 6:04 PM
Thank you for submitting feedback on Visual Studio and .NET Framework. Your issue has been routed to the appropriate VS development team for investigation. We will contact you if we require any additional information.
Posted by Microsoft on 1/29/2013 at 9:50 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.