如何在.NET中获取泄漏对象的根路径引用?

时间:2015-09-01 15:06:55

标签: .net memory-management memory-leaks garbage-collection memory-profiling

我的.NET应用程序中存在内存泄漏。与此同时,我知道哪些物体泄露了。但是应该没有提及它。我怎样才能找到参考文件?哪种工具适合它?

2 个答案:

答案 0 :(得分:2)

I appreciate you like to learn how things work under the hood. This should give you a starting point:

  1. Create a good crash dump for .NET.
  2. Get WinDbg from Microsoft. You can install both versions, x86 and x64 so that you can debug both kinds of dumps.
  3. Open the crash dump in WinDbg (use correct bitness).
  4. Set up the symbols
  5. Load the .NET extension, .loadby sos clr (for .NET 4.x, else see here)
  6. Find the object you're looking for using !dumpheap -type MyType
  7. Use !gcroot to see whether the object has root references or not.

For specific problems, ask questions using and tags.

答案 1 :(得分:1)

我建议使用红门ANTS内存分析器并查看Walkthrough: Using ANTS Memory Profiler to track down a memory leak