开发者

WPF application not releasing memory on logout

开发者 https://www.devze.com 2023-03-14 15:03 出处:网络
I am working on a WPF application which doesnot seem to release all the memory when logged out of a screen. On start of app, there is a login screen where I enter userID/Pwd. It takes to a different s

I am working on a WPF application which doesnot seem to release all the memory when logged out of a screen. On start of app, there is a login screen where I enter userID/Pwd. It takes to a different screen(lets say WPF2). At this point, I am totally unloading the login screen(memory now is 70MB). WHen the WPF2 screen is loaded with dynamically memory goes upto 200MB. When the user logs out from WPF2, login screen loads again. AT this point, I am clearing all objects used in WPF2 开发者_如何学编程in dispose method. But the memory is still 200MB not 70MB, and also when I login again it increases from there.

WHen the application is closed, all memory used is released.

I understand this is very application specific question, but any general ideas are highly appreciated.

Thanks


Items are not released from memory when an event handler is still attached to them, or when the application closes.

This sounds like you have some event handlers to clean up.

Hope this Helps,


You gave not enough information about how you get the memory values. I assume you looked in task manager? If you look only at task manager, you will probably not get the values you expect. Furthermore, memory releasing is not done in the moment a object is no more used. It is an asynchronous task done by the Garbage Collection. If you want to measure memory at a specific point of time, you probably should force GC to free memory before (but only for measurement, not for production code). Look at this thread to get a starting point about the different memory types.

Here you find a very good video, that gives a start to debug memory problems in WPF.


When you call Dispose()on a IDisposableyou can clear umanaged resources.
The GarbageCollector may not have collected WPF2 yet.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号