fundamentals
Analyzing GC spikes and frequent Full GCs in production.
Detection and Analysis:
- GC Logs: Use
-Xlog:gc(Java 9+) or-XX:+PrintGCDetails. Check frequency and duration. - JFR (Java Flight Recorder): Analyze "GC Events" to see which generation is filling up.
- Heap Dump: Use
jmaporjcmdto trigger a dump. Analyze with Eclipse MAT to find memory leaks.
Common Causes:
- Memory Leak: Objects not being released (check static collections).
- Undersized Heap: Heap is too small for the load.
- Large Object Allocation: Humongous objects bypass young gen and go to old gen.
Resolution:
- Tune
-Xmxand-Xms. - Change GC strategy (e.g., switch to G1GC or ZGC).
- Optimize code to reduce object churn.