title: Unable to release WPF Image memory
body: <p>This is a duplicate of <a href="https://stackoverflow.com/questions/63544726/wpf-severe-image-memory-leak">WPF severe Image memory leak</a>,
  however, that one got closed for being  a duplicate. The duplicate question that question got referred to doesn't answer my question, as it just says it's normal and will be picked up by GC.</p>
  <p>However in this case scenario my app will be run in low-resource situations, so it's imperative that the Image is released. Is there any ways to forcefully release the memory used by the Image?
  Here is the code (Note, this is THE ENTIRE CODE, no other references)</p>
  <pre><code>public Window1()
  {
      InitializeComponent();
      BitmapImage bi = new BitmapImage();
      bi.BeginInit();
      bi.CacheOption = BitmapCacheOption.OnLoad;
      bi.UriSource = new Uri(@&quot;C:\users\bb\pictures\wallpaper.png&quot;);
      bi.EndInit();
      bi.Freeze();
      Test.Source = bi;
  }
  
  internal void Delete()
  {
      Test.Source = null;
      Test.UpdateLayout();
      Root.Children.Remove(Test);
  }
  
  private Window1 window1;
  public MainWindow()
  {
      InitializeComponent();
      window1 = new Window1();
      window1.Show();
  }
  
  private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
  {
      window1.Delete();
      window1.Close();
      window1 = null;
  
      GC.AddMemoryPressure(1000000000);
  
      GC.Collect();
      GC.WaitForPendingFinalizers();
      GC.WaitForFullGCComplete();
      GC.Collect();
      GC.Collect();
      GC.WaitForPendingFinalizers();
      GC.WaitForFullGCComplete();
      GC.Collect();
      GC.Collect();
      GC.WaitForPendingFinalizers();
      GC.WaitForFullGCComplete();
      GC.Collect();
      GC.Collect();
      GC.WaitForPendingFinalizers();
      GC.WaitForFullGCComplete();
      GC.Collect(); //Doesn't help
  }
  </code></pre>
  <p>I have also used DotMemory to force a GC numerous times, however, 190MB unmanaged memory still remains. This is just like the accepted answer <a href="https://stackoverflow.com/questions/49072438/wpf-image-control-not-disposing-source">WPF Image control not disposing source</a>, however that question does not answer how to release the memory.</p>