Memory Leak Fix for DeckWorkspace in CAB Extensions for WPF
The P&P Sustained Engineering Team has found a fix for the DeckWorkspace memory leak issue of the Composite UI Application Block Extensions for WPF.
Content
Symptom
When you use a DeckWorkspace workspace 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.
Cause of issue
Summary: Some objects (like instances of LayoutEventArgs class) still reference to the View after it is disposed not allowing it to be swept from memory.
Full description: Using the ANTS profiler tool, we found out that there are some references to the WPF View that do not allow the View to be released from memory after it is shown in a DeckWorkspace workspace. The following figure shows the View2 still in memory even after it had been closed in our application. Should have been swept but the references shown in the bottom left do not allow that.
If you look at the Control class (DeckWorkspace inherits this class) using Reflector, you can see that there is a cachedLayoutEventArgs field that sometimes holds a reference to LayoutEventArgs, which ultimately holds a reference the view in this scenario. Once you call PerformLayout on the control, this reference gets released.
Fix
Summary: Call the PerformLayout method when a View is being closed in the DeckWorkspace, which releases all remaining references to the View.
Step by step: You will need to have installed the SCSF source code and perform the following steps to fix the issue:
- Open the CompositeUI-WPFExtensions.sln solution.
- Right-click in the DeckWorkspace.cs file located in the Workspaces folder on the CompositeUI.WPF project and then select View Code.
- Locate the Close method of the DeckWorkspace class and add the following bold line:
public void Close(object smartPart) { composer.Close(smartPart); // Add this line. this.PerformLayout(); }
- Locate the OnClose method of the DeckWorkspace class and add the following bold line:
protected virtual void OnClose(Control smartPart) { this.Controls.Remove(smartPart); smartPart.Disposed -= ControlDisposed; ActivateTopmost(); // Add this line this.PerformLayout(); }
Download
- CompositeUIWPFAssemblies_fixed.zip: Fixed binaries of the Composite UI Application Block Extensions for WPF (not signed).
- CompositeUIWPFSources_fixed.zip: Fixed source code of the Composite UI Application Block Extensions for WPF.
Enjoy.

