Note that there are some explanatory texts on larger screens.

plurals
  1. POAvalonDock DocumentContent not garbage collected
    primarykey
    data
    text
    <p>I have created an application that makes use of the AvalonDock framework. A key part is the ability to edit domain-model entities using <code>AvalonDock.DocumentContent</code> derived editors. I hit upon a problem and discovered the my editors are not being garbage collected after they are closed and removed from the <code>DockingManager.Documents</code> collection.</p> <p>After some fruitless searching I created a small test application that can be recreated in the following manner:</p> <ul> <li>In Visual Studio (I'm using 2008), create a new WPF application called <code>AvalonDockLeak</code>;</li> <li>Add a reference to the AvalonDock library (my version is 1.3.3571.0);</li> <li>Add a new UserControl called <code>Document</code>;</li> <li><p>Change Document.xmal to:</p> <pre><code>&lt;ad:DocumentContent x:Class="AvalonDockLeak.Document" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ad="clr-namespace:AvalonDock;assembly=AvalonDock"&gt; &lt;Grid&gt; &lt;TextBox /&gt; &lt;/Grid&gt; &lt;/ad:DocumentContent&gt; </code></pre></li> <li><p>Change Document.xmal.cs to:</p> <pre><code>namespace AvalonDockLeak { using AvalonDock; public partial class Document : DocumentContent { public Document() { InitializeComponent(); } ~Document() { } } } </code></pre> <p>The destructor I have added to be able to diagnose the problem adding a breakpoint on the methods opening {, and seeing if it gets hit. It always does on closing the test application but not earlier.</p></li> <li><p>Now change Window1.xaml to:</p> <pre><code>&lt;Window x:Class="AvalonDockLeak.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ad="clr-namespace:AvalonDock;assembly=AvalonDock" Title="Memory Leak Test" Height="300" Width="300"&gt; &lt;Grid&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="Auto" /&gt; &lt;RowDefinition /&gt; &lt;/Grid.RowDefinitions&gt; &lt;Button Name="NewButton" Click="NewButton_Click" Content="New" Height="26" Width="72" /&gt; &lt;ad:DockingManager x:Name="DockManager" Grid.Row="1"&gt; &lt;ad:DocumentPane /&gt; &lt;/ad:DockingManager&gt; &lt;/Grid&gt; &lt;/Window&gt; </code></pre></li> <li><p>Change Window1.xaml.cs to:</p> <pre><code>namespace AvalonDockLeak { using System.Windows; public partial class Window1 : Window { private int counter = 0; public Window1() { InitializeComponent(); } private void NewButton_Click(object sender, RoutedEventArgs e) { string name = "Document" + (++this.counter).ToString(); var document = new Document() { Name = name, Title = name, IsFloatingAllowed = false }; document.Show(this.DockManager); document.Activate(); } } } </code></pre></li> </ul> <p>This simple application also contains the leak. Which can be observed by the breakpoint on the <code>~Document()</code> opening { not getting hit after closing a <code>DocumentContent</code>.</p> <p>Now what I want to now is, is this a known problem and is there a way to prevent it? If the objects are only garbage collected after a long time then what can I do to expedite this? Calling GC.Collect() does not help by the way.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload