1

I have a memory leak in my .NET application. In the meantime I know which objects are leaked. But there should be no references to it. How can I find the reference pathes? Which tool is the right solution for it?

CharithJ
  • 46,289
  • 20
  • 116
  • 131
Horcrux7
  • 23,758
  • 21
  • 98
  • 156
  • 1
    WinDbg or .Net Memory Profiler (not free). Get a full memory dump and then open it in one of the tools. – xxbbcc Sep 01 '15 at 15:11
  • This could be helpful to start (not sure): http://stackoverflow.com/questions/28102678/iterating-through-dumpheap-output-to-read-value-at-memory-offset – xxbbcc Sep 01 '15 at 15:26
  • Also, SOS.dll - https://msdn.microsoft.com/en-us/library/bb190764%28v=vs.110%29.aspx – xxbbcc Sep 01 '15 at 15:29

2 Answers2

3

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.

Community
  • 1
  • 1
Thomas Weller
  • 55,411
  • 20
  • 125
  • 222
1

I would suggest Red gate ANTS Memory profiler and have a look at Walkthrough: Using ANTS Memory Profiler to track down a memory leak

CharithJ
  • 46,289
  • 20
  • 116
  • 131