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
  • 317,000
  • 35
  • 244
  • 286
Franz Kafka
  • 10,623
  • 20
  • 93
  • 149

2 Answers2

5

You can use -XX:+HeapDumpOnOutOfMemoryError

Andrew T Finnell
  • 13,417
  • 3
  • 33
  • 49
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,912
  • 2
  • 19
  • 21