如何使用转储文件来诊断内存泄漏? [英] How do I use a dump file to diagnose a memory leak?

查看:26
本文介绍了如何使用转储文件来诊断内存泄漏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 .NET 服务,它有一个大约 80 MB 的普通私有工作集.在最近的一次负载测试中,进程达到了 3.5 GB 内存使用率,导致整个机器的物理内存不足(使用了 4 GB 中的 3.9 个),并且在负载测试停止后很久没有释放内存.使用任务管理器,我获取了进程的转储文件并在 Visual Studio 2010 SP1 中打开它,然后我就可以开始调试了.

I have a .NET service with a normal private working set of about 80 MB. During a recent load test, the process reached 3.5 GB memory usage causing the whole machine to be low on physical memory (3.9 of 4 GB used), and the memory was not released long after the load test was stopped. Using task manager, I took a dump file of the process and opened it in Visual Studio 2010 SP1, and I am able to start debugging on it.

如何诊断内存问题?我可以使用 dotTrace Memory 3.x,它是否支持对转储文件进行内存分析?如果没有,Visual Studio 2010 Premium 的内存分析功能是否有帮助(我目前拥有 Professional)?WinDbg 可以提供帮助吗?

How do I diagnose the memory issue? I have dotTrace Memory 3.x at my disposal, does it support memory profiling on dump files? If not, will the memory profiling features of Visual Studio 2010 Premium help (I currently have Professional)? Can WinDbg help?

更新:新的 Visual Studio 2013 Ultimate 现在可以使用转储文件在本机诊断内存问题.请参阅 这篇博文 了解更多详情.

UPDATE: The new Visual Studio 2013 Ultimate can now natively diagnose memory issues using dump files. See this blog post for more details.

推荐答案

安装 WinDbg.您需要确保根据您的转储获得正确的 x86 或 x64 版本.这是 下载 x86.

Install WinDbg. You need to make sure you get the correct version x86 or x64 depending on your dump. Here is a direct link to the download for x86.

在这方面,您需要确保进行了正确的转储.您可以使用任务管理器创建转储文件(右键单击进程 -> 创建转储文件).如果您使用的是 64 位并且您的进程是 x86,请使用 32 位版本的任务管理器 (C:WindowsSysWOW64 askmgr.exe) 来获取转储文件.有关获取转储文件的更多信息,请参阅我的文章,例如您使用的是 XP,需要使用 windbg 创建转储文件.

On that, you need to ensure you took the correct dump. You can use Task Manager to create the dump file (right click on process -> Create Dump File). If you're on 64bit and your process is x86 use the 32bit version of Task Manager (C:WindowsSysWOW64 askmgr.exe) to take the dump file. See my article for more info on taking dump files, eg if you're on XP and need to use windbg to create the dump file.

警告有一个相当陡峭的学习曲线,事情可能不像这里描述的那样工作,所以有任何问题请回来.

warning there's a fairly steep learning curve and things might not work exactly as described here so come back with any issues.

我假设您使用的是 .NET4,因为您可以在 Visual Studio 中打开转储.这是一个非常的快速指南,可帮助您处理 dmp 文件:

I'm assuming you're using .NET4 given you can open the dump in Visual Studio. Here's a very quick guide to help you work with your dmp file:

1) 运行WinDbg,设置符号路径(File -> Symbol Search Path)为

1) Run WinDbg, set symbols path (File -> Symbol Search Path) to

SRV*c:symbols*http://msdl.microsoft.com/download/symbols

2) 打开崩溃转储或将您的 .DMP 文件拖到 WinDbg.

2) Open Crash dump or drag your .DMP file onto WinDbg.

3) 在命令窗口中输入这个

3)type this into the command window

.loadby sos clr

(仅供参考,对于 .NET 2,命令应该是 .loadby sos mscorwks)

(FYI, for .NET 2, the command should be .loadby sos mscorwks)

4) 然后输入这个

!dumpheap -stat

列出了对象的类型及其数量.看起来像这样:

which lists the type of objects and their count. looks something like this:

您必须在您的应用程序的上下文中对此进行分析,看看是否有任何异常.

You will have to analyze this in the context of your application and see if anything appears unusual.

windbg 有更多,谷歌是你的朋友.

There is much more to windbg, google is your friend.

这篇关于如何使用转储文件来诊断内存泄漏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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