简体   繁体   中英

detecting object causing memory leak in C#

How to detect objects causing memory leaks in .net. Is it possible to detect object causing memory leaks using crash-dumps?

To detect and investigate memory leaks in .NET you have several options:

  1. Use a memory profiler tool like RedGate's ANTS (many other similar tools are available).
  2. Use WinDBG with its SOS extension.
  3. Instrument your app yourself with a memory leak detector based on weak references.

To use crash dumps in the investigation of memory leaks see this stackoverflow question and this MSDN link.

Having one dump (and if it has been taken properly see this article ) maybe, having multiple dumps most certainly.

What you can do:

  • If you haven´t already, install the Windows SDK to get the Debugging Tools for Windows
  • If you have an x86 process (note: the architecture of the process is relevant, not the architecture of the system running the process) use WinDBG (x86), otherwise use the x64 Version.
  • Go File - Open Crash Dump, locate your dump file and open it
  • assuming your process is .net 4, in the debugger enter

    .loadby sos clr followed by !dumpheap -stat

  • This will output the count and class name of managed types.

  • Having multiple dumps will make it easier for your, but certainly not as easy as being able to use a Memory profiler

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM