Take the 2-minute tour ×

How can I release the memory used by some external resources (images in BitmapImage class) when I close the children window.

In the Task Manager, my application (in WPF with .NET 3.5 in C#) is using ~800,000 KB when the children window is opened with all images loaded, but when I close it, the memory usage is the same, I think that the app doesn't dispose this resources, like the WinForms apps with Dispose(); Method.

share|improve this question
Servy's answer is fairly accurate. But if you are already disposing of your memory then you need to be aware of the fact that it can take some time for GC to clear it. Especially if it is large memory like that. That can end up in the third tier of managed memory. –  SASS_Shooter Feb 11 '13 at 20:08
Have you tried wrap the form in a using statement and then implementing your own Dispose method? –  Ian O'Brien Feb 11 '13 at 20:12
Who about determining if you need those resources , Bitmap Images , etc and Dispose the memory then and there instead of waiting til the window is closed..? another way to do that is instead of calling Dispose then wrap all the stuff that you know will need releasing later around a using(){} clause / statement –  DJ KRAZE Feb 11 '13 at 20:21
add comment

1 Answer

up vote 1 down vote accepted

You can dispose of the resources in a FormClosed event handler.

Another option would be to go to the designer file, add a partial method (partial void AdditionalDisposal();) which you call in the Dispose method, and then you can define an implementation for that partial method in your non-designer code behind in which you dispose of all of the disposable resources you are holding onto.

share|improve this answer
It worked, I created a destructor and some methods, the memory is not released at the moment, but when I open again the window with the pictures the memory is inmediately released and filled again with the data, this is very useful because the memory isn't added to the private space of memory in the program. –  SteelersMan Mar 4 '13 at 18:49
add comment

Your Answer


