
Debug Memory Leak Java Services Running in Production
Debug a Java memory leak in production: confirm the growth, capture histograms and dumps safely, read the dominator tree and fix the holder.
Tag
66 posts

Debug a Java memory leak in production: confirm the growth, capture histograms and dumps safely, read the dominator tree and fix the holder.

How synchronized uses monitors, what lock contention looks like in a thread dump, how to shrink critical sections and what changed for virtual threads.

Understand why the JVM throws GC overhead limit exceeded, capture a heap dump at the failure and decide between a bigger heap and fixing a memory leak.

Manage JDBC transactions by hand: turn off auto commit, commit and roll back, use savepoints, set isolation levels and keep the connection handling safe.

Read the helpful NullPointerException message the JVM prints, find which expression was null and remove the cause instead of adding null checks everywhere.

Use ReentrantLock for timed and interruptible locking and Condition for waiting on state, with a bounded buffer example and the unlock-in-finally rule.

Fix OutOfMemoryError Metaspace by finding out whether the limit is too low, classes are generated without bound or a class loader leaks across redeploys.

Fix NumberFormatException from parseInt and parseDouble by handling whitespace, empty input, overflow and locale-specific separators before you parse.

Use ReentrantReadWriteLock when reads outnumber writes and StampedLock for optimistic reads, with the traps of lock upgrades, reentrancy and measuring first.

Tune G1 by sizing the heap from the container, setting a pause goal and fixing humongous allocations, and leave out the flags that only make it worse.

Read the index and length in the exception, find the off-by-one or empty-input bug that caused it and fix it for arrays, lists and strings.

Fix the Java PKIX path building failed TLS error by finding the missing CA, importing it into a truststore and never disabling verification.