This project is read-only.

Memory Leak Issues

The symptom is that every time you open, close or resize a WPF View, the memory in use increases. The cause of this is related to four known issues:
  1. WPF View is not Disposed correctly
  2. OnCloseView method generated in Presenter classes does not dispose the view
  3. DeckWorkspace bug
  4. Memory usage grows when resizing application windows

WPF C# View is not Disposed correctly

Note: This bug was fixed in SCSF - April 2008 release


The Disposed property implementation located in the View.xaml.GeneratedCode.cs file is incorrect. To solve this issue update the Disposed property of your WPF View with the following code:

public bool Disposed
{
    // get { return _presenter != null && _WPFUIElementAdapter != null; } INCORRECT
    get { return _presenter == null && _WPFUIElementAdapter == null; }  // CORRECT
} 

In order to fix this permanently, you can modify the file View.xaml.GeneratedCode.cs.t4 located at %Program Files%\Microsoft Smart Client Factory\Guidance Package\Templates\Items\View.CS, or modify the guidance package source code and register it again.

See more info related to this issue

OnCloseView method generated in Presenter classes does not dispose the view

To solve this update the OnCloseView method of your View’s presenter class (WPF View) with the following code:

public void OnCloseView()
{
    base.CloseView();
    
    // Add the following code:
    WorkItem.SmartParts.Remove(View);
    if (View is IDisposable)
        ((IDisposable)View).Dispose();
    GC.Collect();
} 

This code does the following:
  1. Remove the View from the Workspace
  2. Remove the View from the Workitem
  3. Dispose the View
  4. Dispose the Presenter (the Dispose method of the View calls the Presenter Dispose method)
See more info related to this issue

DeckWorkspace bug

When you use a DeckWorkspace to show a WPF View, the view will remain in memory even if you call its Dispose method from the presenter. This causes an increase in the memory usage.
To fix this issue you will need to have installed the SCSF source code and perform the following steps:
  • 1. Open the CompositeUI-WPFExtensions.sln solution.
  • 2. Right-click in the DeckWorkspace.cs file located in the Workspaces folder on the CompositeUI.WPF project and then select View Code.
  • 3. Locate the Close method of the DeckWorkspace class and add the following line:
public void Close(object smartPart)
{
    composer.Close(smartPart);

    // Add this line.
    this.PerformLayout();
} 
  • 4. Locate the OnClose method of the DeckWorkspace class and add the following line:
protected virtual void OnClose(Control smartPart)
{
    this.Controls.Remove(smartPart);

    smartPart.Disposed -= ControlDisposed;

    ActivateTopmost();

    // Add this line
    this.PerformLayout();
} 
  • 5. Build the solution.
  • 6. Update the Microsoft.Practices.CompositeUI.WPF.dll assembly in your solution.
See more info related to this issue.

Memory usage grows when resizing application windows

There is a memory leak when resizing a window that contains an ElementHost control. The issue can be reproduced without using SC-SF/CAB and has been escalated to the WPF Team.

Last edited Jul 31, 2008 at 6:59 PM by mconverti, version 7

Comments

dz Oct 13, 2008 at 10:34 AM 
Is there a chance the DeckWorkspace bug will be fixed in the next release?