How do you diagnose a memory leak or high CPU in a JVM app?
⚡
Quick Answer
Capture a heap dump (jmap/jcmd) for leaks and thread dumps or async-profiler flame graphs for CPU, then analyze.
Detailed Answer
For rising memory, take a heap dump (jcmd <pid> GC.heap_dump) and analyze in Eclipse MAT to find dominators. For high CPU, take repeated thread dumps (jstack) or use async-profiler to produce a flame graph showing hot methods. Enable GC logging to distinguish a leak from GC thrash.
💡
Interview Tip
Name the tools: jcmd/jmap, MAT, async-profiler.
jvmheap-dumpprofiling