Note that there are some explanatory texts on larger screens.

plurals
  1. POA WPF transparent window doesn't dispose when closed
    primarykey
    data
    text
    <p>I'm seeing a huge memory leak in a program I'm building using WPF. I've written a small example app which seems to replicate this issue on a smaller scale.</p> <pre><code>public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); images = Directory.GetFiles("C:\\Photos", "*.jpg", SearchOption.TopDirectoryOnly); foreach (string image in images) { Window1 window = new Window1(image); window.Show(); window.Close(); } } } </code></pre> <p>The Window1 XAML . . .</p> <pre><code>&lt;Window x:Class="WpfApplication1.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" AllowsTransparency="True" WindowStyle="None" Background="White" Opacity="1.0" &lt;Grid&gt; &lt;Image Name="pb_Image"/&gt; &lt;/Grid&gt; </code></pre> <p></p> <p>. . . and the Window1 code</p> <pre><code>public Window1(string image) { InitializeComponent(); BitmapImage bi = new BitmapImage(new Uri(image, UriKind.Absolute)); bi.Freeze(); pb_Image.Source = bi; pb_Image.Height = bi.Height; pb_Image.Width = bi.Width; } </code></pre> <p>It repeatedly shows and then closes a window which contains a <code>BitmapImage</code> however an "out of memory exception" occurs very quickly so I'm obviously doing something wrong and hoping someone can point it out!</p> <p><strong>* Update *</strong></p> <p>After playing around for a while I've isolated the issue, this causes a memory leak:</p> <pre><code>foreach (string image in images) { Window1 window = new Window1(image); window.Show(); window.Close(); } </code></pre> <p>and this doesn't</p> <pre><code>foreach (string image in images) { Window1 window = new Window1("C:\\Photos\\photo1.jpg"); window.Show(); window.Close(); } </code></pre> <p>Puzzling - any ideas???</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload