Articles in this section
Category / Section

How to release memory in WPF DockingManager after closing the tab?

1 min read

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 WPF 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;

    }

}


 

 

Conclusion

I hope you enjoyed learning about how to release memory in WPF DockingManager after closing the tab.

You can refer to our WPF DockingManager feature tour page to know about its other groundbreaking feature representations and documentation. You can also explore our WPF DockingManage example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments
Please sign in to leave a comment
Access denied
Access denied