1

Back in the Java world I was able to specify that the JVM should create a heap dump file on the first OutOfMemoryError. Is there anything equivalent in C#?

A heap dump would be ideal but I'd settle for a histogram.

If there's no way to do this automatically is there a way to hook this exception and then walk the heap manually?

chillitom
  • 24,888
  • 17
  • 83
  • 118

2 Answers2

0

You can use the MS Debugging tools ADPlus utility to get a process dump that includes the all the heaps. Then using WinDBG.exe (also in debugging tools) you can use the !DumpHeap command to get all the data you need.

a little old but useful HOWTO link

Menahem
  • 3,974
  • 1
  • 28
  • 43
  • Thanks @Menahem, good suggestion, however I'd really like something that can record the output on users' machines, I won't be able to attach a debugger at the time. – chillitom Mar 11 '12 at 09:49
  • @chillitom in that case you can configure the debugger to take the dump silently on the clients machine , automatically when it happens. then copy the dump to a machine where you can analyse it. Mitch Wheat posted a link to a description of how to get this done. – Menahem Mar 11 '12 at 10:01
0

I would use procdump because you can easily set it up before the crash to dump out the memory when the crash occurs. Then use windbg to look through the memory.

I would add that if it is not immediately obvious where the memory is going (using sos.dll tools command !dumpheap -stat), then you can use procdump to take a number of crash dumps at particular intervals so that you can track what memory is growing.

If you are not familiar with windbg and sos, you might want to check this out.

Davin Tryon
  • 66,517
  • 15
  • 143
  • 132