Rich Dougherty rd.nz

Simple OutOfMemoryError profiling with VisualVM

Today I used Java heap profiling to investigate a problem with Scala futures.

  1. Start your Java program with the following options. I used a maximum heap size of 32 megabytes to speed up the error. When an OutOfMemoryError occurs, a heap profile file will be dumped.

    -Xmx32m -XX:+HeapDumpOnOutOfMemoryError
    
  2. Start VisualVM. On Mac OS 10.8 it is located at the following location:

    /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/jvisualvm
    
  3. Choose File > Load and open the heap profile (hprof) file.

  4. You’ll be presented with a summary of class memory usage.

  5. Investigate!