Hi I’m bringing back some items from a web service that contains three strings. One of those is the path to an image. Now when I start loading the images into a listbox the memory as expected starts to go up which isn’t bad. But when I hit the back button the memory is still very high.
I’m thinking it has to do with the fact that I’m not releasing the resources taken up by the images. The idea comes from this answer => Question.
Does anyone know how to manually release these resources?
There’s no Dispose() method for Image or BitmapImage classes, so the best you can do is dispose the stream you’re getting the data to. But I’d personally look for the problem somewhere else since Images should be GC’d automatically (in fact, they do).
There might be event handlers that bind to your page from outside making GC unable to collect it, e.g. you have a reference to the page in your application settings or something. Or the GC just doesn’t at once collect the dumped objects but waits for the specific time – try moving back/forward several times and see if the memory raises up and up and up.
Anyway, there’s no need/ability to free resources taken by Image/BitmapImage manually (only the corresponding Stream, which usually doesn’t give the result since it’s cached in the image).