简体   繁体   English

WPF / Winform应用程序中的内存占用量不断增加

[英]Memory footprint constantly increasing in WPF/Winform application

This issue seems to be isolated to the part of my program where I have a Winform control hosted inside a WPF window. 这个问题似乎与我的程序部分无关,在WPF窗口中托管了Winform控件。

The user is presented with X number of rows, and may click Edit on any row to bring up another window (<< this is the window with the Winform control in it). 向用户显示X行,可以在任何行上单击“编辑”以打开另一个窗口(<<这是其中包含Winform控件的窗口)。

Every time a new selection is made, and a new Edit window is loaded, the memory usage goes up between 1 and 4 megs. 每次进行新的选择并加载新的“编辑”窗口时,内存使用量都会增加1至4兆。 I have tried nulling/disposing all the objects I can when that window is closed, but it hasn't made a difference. 我已经尝试过在该窗口关闭时使所有对象都可以置零/布置,但是并没有什么改变。

It is ONLY this window that causes the memory to go up consistently and it never goes back down. 只有此窗口会导致内存持续增加,而永远不会回落。 Even if I close all but the Main window, the memory footprint stays where it is. 即使关闭除“主”窗口之外的所有窗口,内存占用量仍保持在原位。

Simpliest solution is to make memory snapshot of your memory before opening window and after and see what new object were allocated. 最简单的解决方案是在打开窗口之前和之后制作内存快照,并查看分配了哪些新对象。 You can do it with memory profiler dotMemory for example. 例如,您可以使用内存分析器dotMemory来完成此操作。

Also in dotMemory you can automatically see what event handlers are leaked. 同样在dotMemory中,您可以自动查看泄漏了哪些事件处理程序。

Alexey has said how I would approach this problem as well. 阿列克谢(Alexey)曾说过我也将如何解决这个问题。 Profiling the memory can show a lot of issues with a program. 对内存进行性能分析可能会显示程序的许多问题。

Microsoft provides two tools that you can use for this. Microsoft提供了两个可用于此目的的工具。 One is the CLR Profiler and the other is the Performance Analysis Tool which also includes memory CLR memory information. 一个是CLR Profiler ,另一个是性能分析工具 ,它还包括内存CLR内存信息。 I would go with the former of these two. 我会选择前两者。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM