First you need to get the heap dump(.hprof): There are several ways to go about this.
- Run JVM with
-XX:+HeapDumpOnOutOfMemoryError
so that JVM will automatically produce a heap dump when it hitsOutOfMemoryError
. - You can run
jmap -dump:live,file=/tmp/jenkins.hprof pid
where pid is the process ID of the target Java process. - Use VisualVM, attach to the running instance, and obtain a heap dump
- If your Jenkins runs at
http:
//server/jenkins/
, requesthttp:
//server/jenkins/heapDump
with your browser and you’ll get the heap dump downloaded. (1.395 and newer) - If you are familiar with one of many Java profilers, they normally offer this capability, too.
Then you need to do a Heap Dump Analysis with a tool like Eclipse Memory Analyzer you can then check the suspects and view the java classes to find the culprit.
I recommend using a powerful machine to run MAT if your heap dump is large. By default, MAT is limited to 1GB of memory usage, so I suggest adjusting it to match your machine’s available capacity by modifying the “-Xmx” flag in the “MemoryAnalyzer.ini” configuration file. Once you load the heap dump, be prepared to wait, as it can take a significant amount of time to load and analyze.