How to release memory in DockingManager after closing the tab?
Remove the child from DockingManager
Closed children are moved to the “Hidden dock state” so that it does not release memory. You have to manually remove the children from DockingManager in DockStateChanged event.
Remove memory held by Automation peer
DocumentContainer of DockingManager is derived from the base of Tab control. Normally TabItems Automation peer holds some memory. That memory also needs to be released by the FakeWindowAutomationPeer method as follows.
Create FakeWindowAutomationPeer class
Create a new class derived from WindowAutomationPeer class and define the override method GetChildrenCore(), and define OnCreateAutomationPeer() override method in MainWindow.
MainWindow.xaml
<Window x:Class="DockingManager_131769.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:syncfusion="http://schemas.syncfusion.com/wpf" Title="MainWindow" Height="350" Width="525"> <Grid> <syncfusion:DockingManager DockStateChanged="Docking_DockStateChanged" UseDocumentContainer="True" x:Name="Docking"/> </Grid> </Window>
MainWindow.xaml.cs
public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } //Remove child from DockingManager private void Docking_DockStateChanged(FrameworkElement sender, DockStateEventArgs e) { if(e.NewState==DockState.Hidden) Docking.Children.Remove(sender); } protected override AutomationPeer OnCreateAutomationPeer() { return new FakeWindowsPeer(this); } } public class FakeWindowsPeer : WindowAutomationPeer { public FakeWindowsPeer(Window window): base(window) { } protected override List<AutomationPeer> GetChildrenCore() { return null; } } |