I am filling a Listbox with different images:
ListBoxItem itm = new ListBoxItem();
var bitmap = new BitmapImage();
var img = new Image();
var stream = File.OpenRead(e.FullPath);
bitmap.BeginInit();
bitmap.CacheOption = BitmapCacheOption.OnLoad;
bitmap.StreamSource = stream;
bitmap.EndInit();
stream.Close();
stream.Dispose();
img.Source = bitmap;
itm.Content = img;
galerielb.Items.Insert(0, itm);
if (galerielb.Items.Count > 9)
galerielb.Items.RemoveAt(galerielb.Items.Count - 1);
The last Line does not free up the memory used by the image? How can I free it in the above code?