WPF memory issue with images

Viewed 2492

I seem to be having some big memory consumption issues. When I first load my wpf application which contains a gridview and an observablecollection the app is around 10mb.

When I click on an item in the gridview it opens another window which contains an image control which gets passed a base64 string that I then convert into a BitmapImage

The application then jumps up to around 123mb from 10mb. The original image size is 64k but all my stored images are base64 strings that I convert back to byte[] then into a BitmapImage. Yes I mean to do this.

When I close the window none of the ram gets release. I've even tried calling GC.

I use the following code to turn the base64 image into

var bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.CacheOption = BitmapCacheOption.None;
bitmapImage.StreamSource = new SIO.MemoryStream(imageBytes);
bitmapImage.EndInit();
return bitmapImage;

That then gets assigned to Image.Source

2 Answers
Related