title: MemoryLeak with converter
body: <p>While using converter as static resource in custom control Memory leak occurs even when the window is closed.</p>
  
  <p>Sample attached and please find the screenshot below.</p>
  
  <p>Can you please suggest any solution for this?</p>
  
  <p>Note: I have checked this in ANTS profile. </p>
  
  <p><a href="https://i.stack.imgur.com/Y7hAC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Y7hAC.png" alt="enter image description here"></a></p>
  
  <p><a href="https://drive.google.com/open?id=1hwBNVWBv0YG94hdlJnc2W-IV71xuZD_t" rel="nofollow noreferrer">Sample link</a></p>
  
  <p>Sample code to create custom control. This control used in simple sample.</p>
  
  <p><strong>Memory leak replication steps with sample description:</strong></p>
  
  <p>Use the created custom control in simple sample.</p>
  
  <p>Before and after closing the window, (which window have the created custom control) check memory leak in ANTS profile.</p>
  
  <pre><code>&lt;ResourceDictionary
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:local="clr-namespace:customcontrol"&gt;
  
      &lt;local:YesNoToBooleanConverter x:Key="YesNoToBooleanConverter"/&gt;
  
  &lt;Style TargetType="{x:Type local:CustomControl1}"&gt;
      &lt;Setter Property="Template"&gt;
          &lt;Setter.Value&gt;
              &lt;ControlTemplate TargetType="{x:Type local:CustomControl1}"&gt;
                  &lt;Border Background="{TemplateBinding Background}"
                          BorderBrush="{TemplateBinding BorderBrush}"
                          BorderThickness="{TemplateBinding BorderThickness}"&gt;
                      &lt;StackPanel Orientation="Horizontal"&gt;
                      &lt;TextBox Name="txtValue" Height="50" Width="100" /&gt;
                      &lt;CheckBox IsChecked="{Binding ElementName=txtValue, 
                                        Path=Text, 
                                        Converter={StaticResource YesNoToBooleanConverter}}" /&gt;
                      &lt;/StackPanel&gt;
                  &lt;/Border&gt;
              &lt;/ControlTemplate&gt;
          &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
  &lt;/Style&gt;
  </code></pre>
  
  <p> </p>
  
  <hr>
  
  <pre><code>public class CustomControl1 : Control
  {
      static CustomControl1()
      {
          DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomControl1), new FrameworkPropertyMetadata(typeof(CustomControl1)));
      }
  }
  
  public class YesNoToBooleanConverter : IValueConverter
  {
      public object Convert(object value, Type targetType, object parameter,
              System.Globalization.CultureInfo culture)
      {
          switch (value.ToString().ToLower())
          {
              case "yes":
                  return true;
              case "no":
                  return false;
  
              default:
                  return Binding.DoNothing;
          }
      }
  
      public object ConvertBack(object value, Type targetType, object parameter,
              System.Globalization.CultureInfo culture)
      {
          if (value is bool)
          {
              if ((bool)value == true)
                  return "yes";
              else
                  return "no";
          }
          return "no";
      }
  }
  </code></pre>
  
  <p>Regards,
  Priyanga B</p>