-Xmx sets the maximum heap size available to a Java application at startup. For example, -Xmx1G permits a heap of up to 1 GB. section 5.2.3
Use -Xmx when memory pressure suggests insufficient heap capacity. Peaks and valleys in usage indicate garbage collection is reclaiming memory; steadily rising usage suggests a leak that more heap only delays. section 5.2.3 section 11.4.3
Investigate heap pressure by asking:
- Does garbage collection reclaim enough memory, or does usage keep climbing toward the limit? section 5.2.3 section 11.4.3
- Would increasing -Xmx provide short-term relief while application logic reduces unnecessary allocations? section 11.4.3
- Does the application require a heap dump to identify retained objects after an OutOfMemoryError? section 5.2.3
Reading a full-GC pattern
A log entry such as Full GC (Allocation Failure) 8192M->6100M(8192M) shows an 8-GB maximum heap and memory remaining after collection. Repeated full collections with high usage indicate pressure; increasing -Xmx may help temporarily. section 11.4.3
[GC pause (G1 Evacuation Pause) (mixed), 0.01506789 secs] [GC pause (G1 Evacuation Pause) (mixed), 0.01783456 secs] [GC pause (G1 Evacuation Pause) (mixed), 0.02021234 secs] [Full GC (Allocation Failure) 8192M->6100M(8192M), 2.345678 secs] [GC pause (G1 Evacuation Pause) (mixed), 0.01901234 secs] [GC pause (G1 Evacuation Pause) (mixed), 0.02115678 secs] [Full GC (Allocation Failure) 8192M->5800M(8192M), 2.678901 secs] [GC pause (G1 Evacuation Pause) (mixed), 0.0987654 secs] [GC pause (G1 Evacuation Pause) (mixed), 0.02254321 secs] [Full GC (Allocation Failure) 8192M->5600M(8192M), 2.789012 secs]
Inspect repeated Full GC entries to compare heap capacity, reclaimed memory, and collection duration. section 11.4.3
