title: Why does a WPF UserControl with a binding not get Garbage Collected?
body: <p>Our application adds and removes WPF (4.0) UserControls from it's main window, and we've noticed that they are not getting Garbage Collected (via WeakReferences that never return null). It seems that if a UserControl has a binding this occurs, even if the control was never added to the tree. The simplest reproduction in a <strong>console application</strong> follows:</p>
  
  <p><em>Main Program</em></p>
  
  <pre><code>class Program
  {
      [STAThread]
      static void Main(string[] args)
      {
          var obj = GetObj();
          var ctl = GetCtl();
          for (int x = 0; x &lt; 4; x++)
          {
              GC.Collect();
              Thread.Sleep(1000);
          }
          bool objAlive = obj.IsAlive;
          bool ctlAlive = ctl.IsAlive;
          Console.WriteLine(objAlive + "-" + ctlAlive);
          Console.ReadLine();
      }
  
      private static WeakReference GetObj()
      {
          return new WeakReference(new object());
      }
  
      private static WeakReference GetCtl()
      {
          return new WeakReference(new MyCtl());
      }
  }
  </code></pre>
  
  <p><em>MyCtl User Control (Code behind is standard and has not been modified</em></p>
  
  <pre><code>&lt;UserControl &lt;!--Snip Default Namespaces--&gt;&gt;
      &lt;TextBlock Text="{Binding Blah}" /&gt;
  &lt;/UserControl&gt;
  </code></pre>
  
  <p>objAlive is false, but ctlAlive is true. If the Binding is removed from the UserControl XAML, both are false. If I connect a memory profiler, MyCtl is still hanging around, but I can't figure out what is referencing it (tips on how to find this using the jetBrains one is appreciated).</p>
  
  <p>Is this expected behaviour or do I need to do more to clean up my WPF UserControls?</p>