GC Tuning Flags and JVisualVM Profiling
Set heap size flags, enable GC logging, and use JVisualVM to profile heap usage in a live app.
Why Tune GC?
Default GC settings work well for many apps, but high-throughput or low-latency workloads may need tuning. Measure first — never tune blindly.
Heap Size Flags
Set initial (-Xms) and maximum (-Xmx) heap. In production, set them equal to prevent dynamic resizing pauses. Start with 60-70% of available RAM.
// Example production flags:
java -Xms2g -Xmx2g -XX:+UseG1GC MyApp
// Avoid:
java -Xmx8g MyApp // initial = 256m, max = 8g → resizing pausesAll lessons in this course
- JVM Heap Regions and Object Lifecycle
- GC Algorithms: Serial, G1, ZGC, Shenandoah
- Detecting and Fixing Memory Leaks
- GC Tuning Flags and JVisualVM Profiling