title: How to solve memory leak in WPF, caused of DependencyProperty OverrideMetadata?
body: <p>I have an WPF application. I have a button, that opens modal window in it, using <strong>ShowDialog()</strong> for that.I found that my modal window, is cause of memory leak, it's never getting disposed, and is getting allocated a new instance each time.</p>
  
  <p>After going deep in code, and using ANTS profiler, I found, that cause of the leak, was this lines below. I'm using custom Styles for my APP. When I'm removing Styles from XAML file, window is getting disposed properly.</p>
  
  <p><strong>What is wrong in this static Constructor? it's the reason for leak.</strong> </p>
  
  <pre><code>   static StyleWindow()
  {
     StyleProperty.OverrideMetadata(typeof(StyleWindow),new 
     FrameworkPropertyMetadata(Application.Current.FindResource(typeof(StyleWindow))));
  } 
  
  //StyleProperty definition
  public static readonly DependencyProperty StyleProperty;
  </code></pre>
  
  <p>Thanks a lot, any help and ideas appreciated!</p>