title: How to dispose user control with free memory when tab change in WPF
body: <p>I am using infragistics TabGroupPane. In that case i am loding User control when ContentPane is active and remove previously active tab content.
  here is my code Xaml : </p>
  
  <pre><code>&lt;igDock:DocumentContentHost&gt;
                  &lt;igDock:SplitPane&gt;
                      &lt;igDock:TabGroupPane x:Name="tabMainMenu" SelectionChanged="xamMainTab_SelectionChanged" AllowDrop="False"&gt;
                          &lt;igDock:ContentPane x:Name="tabItem1"  Header="Item 1"&gt;&lt;/igDock:ContentPane&gt;
                          &lt;igDock:ContentPane x:Name="tabItem2"  Header="Item 2"&gt;&lt;/igDock:ContentPane&gt;
                          &lt;igDock:ContentPane x:Name="tabItem3"  Header="Item 3"&gt;&lt;/igDock:ContentPane&gt;
                          &lt;igDock:ContentPane x:Name="tabItem4"  Header="Item 4"&gt;&lt;/igDock:ContentPane&gt;
                          &lt;igDock:ContentPane x:Name="tabItem5"  Header="Item 5"&gt;&lt;/igDock:ContentPane&gt;
                      &lt;/igDock:TabGroupPane&gt;
                  &lt;/igDock:SplitPane&gt;
              &lt;/igDock:DocumentContentHost&gt;
  </code></pre>
  
  <p>and code behide side</p>
  
  <pre><code>private void xamMainTab_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
      {             
          if (e.RemovedItems.Count &gt; 0 &amp;&amp; null != e.RemovedItems[0] as ContentPane)
          {
              (e.RemovedItems[0] as ContentPane).Content = null;
          }
          GC.Collect();
          ContentPane selectedTab = this.tabMainMenu.SelectedItem as ContentPane;         
          BindContainer(selectedTab.Name);
      }
  private void BindContainer(string item)
      {
          switch (item)
          {
              case "tabItem1":
                  this.tabItem1.Content = new UserControls.UserControl1();
                  this.tabMainMenu.SelectedItem = this.tabItem1;
                  break;
              case "tabItem2":
                  this.tabItem2.Content = new UserControls.UserControl2();
                  this.tabMainMenu.SelectedItem = this.tabItem2;
                  break;
              case "tabItem3":                    
          this.tabItem3.Content = new UserControls.UserControl3();
                  this.tabMainMenu.SelectedItem = this.tabItem3;
                  break;
              case "tabItem4":
                  this.tabItem4.Content = new UserControls.UserControl4();
                  this.tabMainMenu.SelectedItem = this.tabItem4;
                  break;
              case "tabItem5":                    
                  this.tabItem5.Content = new UserControls.UserControl5();
                  this.tabMainMenu.SelectedItem = this.tabItem5;
                  break;
              default:
                  this.tabItem1.Content = new UserControls.UserControl1();
                  this.tabMainMenu.SelectedItem = this.tabItem1;
                  break;
          }
      }
  </code></pre>
  
  <p>here i set content of last item to null.(e.RemovedItems[0] as ContentPane).Content = null;
  but in that case memory(size) does not free.and then i use GC.Collect,this time some memory are free.
  Is this write way to free memory or any other way then please provide me any reference of that.And also In this case when my user control contain WebBrowser then memory does not free if i use GC.collect please guide me on this also.</p>
  
  <p>Thanks</p>