简体   繁体   English

Memory 泄漏 wpf C#

[英]Memory leaks in wpf C#

I am developing a WPF MVVM (in v3.5) application using GalaSoft.MvvmLight suite and WPF Toolkit for DataGrid and DatePicker .我正在使用 GalaSoft.MvvmLight 套件和 WPF Toolkit for DataGridDatePicker开发 WPF MVVM(在 v3.5 中)应用程序。 However I am facing lots of memory leaks in the application every time I load a UserControl in MainWindow .但是,每次我在MainWindow中加载UserControl时,我都会在应用程序中面临很多 memory 泄漏。 I am trying to get the exact issue via Scitech Memory profiler, though I have some serious questions:我试图通过 Scitech Memory 分析器得到确切的问题,尽管我有一些严重的问题:

  1. How to unhook/unbind the RelayCommand from the Event in VM?如何从 VM 中的Event中取消挂钩/取消绑定RelayCommand
  2. mscorlib and PresentationFramework are also consuming lots of memory and most of them are strings . mscorlib 和 PresentationFramework 也消耗了大量的 memory 并且其中大部分是strings I don't know where they are coming from.我不知道他们从哪里来。

Please help.请帮忙。

Have a look at these articles to know causes of memory leaks in WPF, there solutions and how to find them -查看这些文章以了解 WPF 中 memory 泄漏的原因,有解决方案以及如何找到它们 -

Finding Memory Leaks in WPF-based applications:在基于 WPF 的应用程序中查找 Memory 泄漏:

http://blogs.msdn.com/b/jgoldb/archive/2008/02/04/finding-memory-leaks-in-wpf-based-applications.aspx http://blogs.msdn.com/b/jgoldb/archive/2008/02/04/finding-memory-leaks-in-wpf-based-applications.aspx

Memory Leaks in WPF applications: Memory WPF 应用程序中的泄漏:

http://svetoslavsavov.blogspot.com/2010/05/memory-leaks-in-wpf-applications.html http://svetoslavsavov.blogspot.com/2010/05/memory-leaks-in-wpf-applications.html

Finding Managed Memory Leaks in WPF and Silverlight applications:查找 WPF 和 Silverlight 应用程序中的托管 Memory 泄漏:

http://blogs.msdn.com/b/wpftesting/archive/2009/03/21/finding-managed-memory-leaks-in-wpf-and-silverlight-applications.aspx http://blogs.msdn.com/b/wpftesting/archive/2009/03/21/finding-managed-memory-leaks-in-wpf-and-silverlight-applications.aspx

In case you are using WPF 3.5 SP1, have a look at these hot-fixes -如果您使用的是 WPF 3.5 SP1,请查看这些热修复 -

Memory Leak Hotfixes for WPF 3.5 SP1 WPF 3.5 SP1 的 Memory 泄漏修补程序

http://blogs.msdn.com/b/jgoldb/archive/2010/06/14/memory-leak-hotfixes-for-wpf-3-5-sp1.aspx http://blogs.msdn.com/b/jgoldb/archive/2010/06/14/memory-leak-hotfixes-for-wpf-3-5-sp1.aspx

Some more rare scenarios causing memory leaks -一些更罕见的情况导致 memory 泄漏 -

http://blog.ramondeklein.nl/?p=58 http://blog.ramondeklein.nl/?p=58

http://code.logos.com/blog/2008/10/detecting_bindings_that_should_be_onetime.html http://code.logos.com/blog/2008/10/detecting_bindings_that_should_be_onetime.html

Are you certain that these are memory leaks?您确定这些是 memory 泄漏吗? are you using the profiler correctly?您是否正确使用了探查器? To confirm that you have a memory leaks you must run the garbage collector so that all the objects that are not references by a stackframe are deleted.要确认您有 memory 泄漏,您必须运行垃圾收集器,以便删除所有未被堆栈帧引用的对象。 Once you have run the garbage collector inspect the heap memory for objects which should have been collected.运行垃圾收集器后,检查堆 memory 是否应该收集对象。

Eg in your application, open a view or document, close it, garbage collector, and then check to see if it has been removed.例如,在您的应用程序中,打开一个视图或文档,关闭它,垃圾收集器,然后检查它是否已被删除。

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

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