title: WPF Usercontrol in Contentcontrol.Content Memory Leak
body: <p>The problem is a memory leak in my prism, autofac .NET 4.5.1 WPF application. I reduced the problem and the problem is also in a native WPF application without prism and autofac.</p>
  
  <p>On startup the application uses 34 MB ram. I set a new instance of a usercontrol with a big ram allocation in the contentcontrol in the mainwindow. The ram goes up to 900 MB. Now i will clean up my ui and i tested to clear the internal collection in the usercontrol, the content of the contentcontrol set to null ... But the ram is on 140 MB. How can i release the ram between the startup and after cleanup.</p>
  
  <p>When i create the usercontrol and not set it in the content of the contentcontrol the ram goes to 38 MB. That is OK. It is possible to release the "complete" ram when i use a usercontrol in another control?</p>
  
  <p>Mainwindow:</p>
  
  <pre><code>&lt;ContentControl x:Name="myContentControl"&gt;&lt;/ContentControl&gt;
  </code></pre>
  
  <p>Code behind:</p>
  
  <pre><code>private void Button_Click_1(object sender, RoutedEventArgs e)
  {
      this.myContentControl.Content = new UserControl1();
  }
  
  private void Button_Click_2(object sender, RoutedEventArgs e)
  {
      this.myContentControl.Content = null;
      GC.Collect();
  }
  </code></pre>
  
  <p>The usercontrol:</p>
  
  <pre><code>&lt;Grid&gt;
      &lt;DataGrid x:Name="myTestListView" Background="Purple" Height="280&gt;&lt;/DataGrid&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>public partial class UserControl1 : UserControl
  {
      private List&lt;string&gt; Testitems = new List&lt;string&gt;(); 
  
      public UserControl1()
      {
          InitializeComponent();
          this.Testitems = new List&lt;string&gt;();
          for (int i = 0; i &lt; 1000000; i++) this.Testitems.Add(i.ToString());
          this.myTestListView.ItemsSource = this.Testitems;
      }
  }
  </code></pre>