How to debug .net Garbage Collection?

后端 未结 2 2025
感情败类
感情败类 2020-12-29 13:10

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

I need to see what objects are still in memory and

相关标签:
2条回答
  • 2020-12-29 13:55

    I use SciTech's Memory profiler. It's a bit complicated to use off the bat, but there are some good instructional videos. It'll let you look at which objects aren't disposed properly, in which generation they were collected. Couldn't debug memory leaks without it...

    0 讨论(0)
  • 2020-12-29 14:06

    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/

    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

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

    .loadby sos mscorwks.dll

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

    0 讨论(0)
提交回复
热议问题