在C#WPF内存泄漏 [英] Memory Leaks in C# WPF

查看:312
本文介绍了在C#WPF内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用在C#跟踪内存泄漏的原因一些建议。我明白了什么是内存泄漏,我得到他们为什么会发生在C#中,但我不知道用什么工具/策略已经你们在过去使用来解决这些问题?

I could use some advice on tracking down the cause of memory leaks in C#. I understand what is a memory leak and I get why they occur in C# but I'm wondering what tools/strategies have you used in the past to resolve them?

我使用.NET内存分析器我发现我的巨大的主要对象之一是留在记忆后,我关闭它管理的窗口,但我不知道该怎么做剧烈的所有链接到它。

I am using .NET Memory Profiler and I've found that one of my huge main objects is staying in memory after I close the window it manages but I'm not sure what to do to severe all links to it.

如果我不是足够清楚的只是后一个问题的答案,我会回应编辑我的问题。谢谢!

If I'm not being clear enough just post an answer with a question and I'll edit my question in response. Thanks!

推荐答案

进入调试器,然后键入到立即窗口这样的:

Break into the debugger and then type this into the Immediate window:

.load C:\Windows\Microsoft.NET\Framework\v2.0.50727\sos.dll

要sos.dll的路径各不相同。找出正确的路径的方法是看在模块窗格中的Mscorwks.dll。无论是从加载是sos.dll正确的路径。

The path to sos.dll varies. The way to find out the correct path is to look for mscorwks.dll in the Modules pane. Wherever that is loaded from is the correct path for sos.dll.

然后键入以下内容:

System.GC.Collect()

这将确保任何收集不可达。然后键入:

That will ensure anything not reachable is collected. Then type this:

!DumpHeap -type <some-type-name>

这会告诉你所有现有实例表,其中地址。你可以找出什么让一个实例的生命是这样的:

This will show you a table of all existing instances, with addresses. You can find out what is keeping an instance alive like this:

!gcroot <some-address>

这篇关于在C#WPF内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆