title: WPF increase memory each time open and close window
body: <p>I have done and very easy test, just to understand the wpf how works with memory.
  I create one project with one window where's a <code>Button</code>.
  And a second window totally empty.
  when I press the <code>Button</code> in click open the second window
  code behind window 1:</p>
  
  <pre><code>/// &lt;summary&gt;
  /// Interaction logic for WindowTest1.xaml
  /// &lt;/summary&gt;
  public partial class WindowTest1 : Window
  {
      public WindowTest1()
      {
          InitializeComponent();
      }
  
      private void Button_Click(object sender, RoutedEventArgs e)
      {
          var wt2 = new WindowTest2();
          wt2.ShowDialog();
          wt2 = null;
      }
  }
  </code></pre>
  
  <p>xaml window 1:</p>
  
  <pre><code>&lt;Window x:Class="WpfAppXtesting.WindowTest1"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      xmlns:local="clr-namespace:WpfAppXtesting"
      mc:Ignorable="d"
      Title="WindowTest1" Height="450" Width="800"&gt;
  &lt;Grid&gt;
      &lt;Button Content="Button" HorizontalAlignment="Left" Height="148" Margin="191,138,0,0" VerticalAlignment="Top" Width="267" Click="Button_Click"/&gt;
  
  &lt;/Grid&gt;
  </code></pre>
  
  <p></p>
  
  <p>code behind window2:</p>
  
  <pre><code> /// &lt;summary&gt;
  /// Interaction logic for WindowTest2.xaml
  /// &lt;/summary&gt;
  public partial class WindowTest2 : Window
  {
      public WindowTest2()
      {
          InitializeComponent();
      }
  }
  </code></pre>
  
  <p>xaml code window2:</p>
  
  <pre><code>&lt;Window x:Class="WpfAppXtesting.WindowTest2"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      xmlns:local="clr-namespace:WpfAppXtesting"
      mc:Ignorable="d"
      Title="WindowTest2" Height="450" Width="800"&gt;
  &lt;Grid&gt;
  
  &lt;/Grid&gt;
  </code></pre>
  
  <p></p>
  
  <p>In the image below I took a screenshot of memory status.
  the first line I took when start only the first window.
  the second line when the second window was open.
  the third line when the second window was close.
  the last list I took after ten time open and close the second window.</p>
  
  <p>Why the memory don't come back to the first list usage? </p>
  
  <p><a href="https://i.stack.imgur.com/8VMlU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8VMlU.png" alt="enter image description here"></a></p>