垃圾收集如何调试? [英] How to debug .net Garbage Collection?

查看:99
本文介绍了垃圾收集如何调试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以查看在调用GC.Collect()?时收集的所有 .net对象?

Is it possible to have a look at all .net objects which are collected upon calling GC.Collect()?

我需要看看什么对象仍然在内存中,没有回收,所以我可以找到在哪里回收对象应该做的手动,但被程序员忘记了

我不想调用GC.Collect因为某人在某处忘记处理阻挡某些句柄的对象。

I need to see what objects are still in memory and not reclaimed, so I can find where reclaiming the objects should have done manual, but was forgotten by the programmer.
I don't want to call GC.Collect because someone somewhere forgot to dispose an object which blocks some handles.

推荐答案

我发现最好的方法是使用windbg和SOS(罢工之子)延伸。它有一个相当神秘的命令行,但它是非常强大的。它具有转储堆并将其划分为GC生成堆的功能。一旦你超过初始的学习曲线,很容易跟踪哪些对象在堆的哪个部分是活着的。以下是一些网站,其中包含使用SOS的示例。

I've found the best way to do this is to use windbg and the SOS (son of strike) extension. It has a rather cryptic command line but it is very powerful. It has the capability to dump the heap and divide it by the GC generational heap. Once you get past the initial learning curve, it's very easy to track what objects are alive in what portion of the heap. Here are a few web sites with examples of using SOS

  • http://blogs.msdn.com/tess/archive/2005/11/25/dumpheap-stat-explained-debugging-net-leaks.aspx
  • http://geekswithblogs.net/.NETonMyMind/archive/2006/03/14/72262.aspx
  • http://dotnetdebug.net/2005/07/04/dumpheap-parameters-and-some-general-information-on-sos-help-system/

编辑 OP询问sos.dll的位置。它包含在.Net框架的安装中。它位于

EDIT OP asked about the location of sos.dll. It is included with the install of the .Net Framework. It is located at


%WINDIR%\Microsoft.Net\Framework\V2.0.50727\sos.dll

%WINDIR%\Microsoft.Net\Framework\V2.0.50727\sos.dll

但是一旦加载了windbg,就不需要完整的路径。只是我们的.loadby方法。

But once you have windbg loaded you don't need the full path. Just us the .loadby method.


.loadby sos mscorwks.dll

.loadby sos mscorwks.dll

它将查找与当前版本的mscorwks(CLR)相同目录中的sos版本

It will look for the version of sos in the same directory as the current version of mscorwks (the CLR)

这篇关于垃圾收集如何调试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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