0

Possible Duplicate:
Java VisualVM Enable Heap Dump on OOME

I've got an App that crashes because of an OOME. I would like to create a dump file of the heap shortly before the App crashes. I used jdump before to analyse the heap after a few hours of runtime, but nothing suspicious was found. I can run the app in some Eclipse profiler. Is there some way to create a heap dump shortly before a OOME is thrown on a server with a normal (or jdk) installation?

trincot
  • 263,463
  • 30
  • 215
  • 251
Franz Kafka
  • 10,303
  • 19
  • 89
  • 148

2 Answers2

5

You can use -XX:+HeapDumpOnOutOfMemoryError

Andrew T Finnell
  • 13,117
  • 2
  • 32
  • 48
0

If you really want to dump heap before you run out of memory, you could add a worker thread that periodically polls for memory usage (see freeMemory). When you start running out of memory, you dump heap.

See https://blogs.oracle.com/sundararajan/entry/programmatically_dumping_heap_from_java for how to dump heap from your application.

Guido Simone
  • 7,782
  • 2
  • 17
  • 19