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

How to get the root path references to leaked objects in .NET?

我的 .NET 应用程序存在内存泄漏。同时我知道哪些对象被泄露了。但不应提及它。我怎样才能找到参考路径?哪个工具是它的正确解决方案?

感谢您喜欢了解事物的内在运作方式。这应该给你一个起点:

  1. 创建 good crash dump for .NET
  2. 从 Microsoft 获取 WinDbg。您可以安装 x86 和 x64 这两个版本,以便您可以调试这两种转储。
  3. 在 WinDbg 中打开故障转储(使用正确的位数)。
  4. 加载 .NET 扩展,.loadby sos clr(对于 .NET 4.x,否则参见 here
  5. 使用 !dumpheap -type MyType
  6. 查找您要查找的对象
  7. 使用!gcroot查看对象是否有根引用。

对于具体问题,请使用 and 标签提问。

我建议使用 Red gate ANTS Memory profiler 并查看 Walkthrough: Using ANTS Memory Profiler to track down a memory leak