liveBook · Manning

-Xmx

As explained in Troubleshooting Java, Second Edition

-Xmx is a JVM startup property that sets the maximum heap size available to a Java application.

-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

How Troubleshooting Java, Second Edition covers it

How deep it goes
Defines startup syntax and diagnostic implications, but defers heap-dump analysis and application-level root-cause fixes.
Examples
Uses -Xmx1G, -Xms500m, memory-usage graphs, OutOfMemoryError traces, and repeated Full GC log entries.
What you can do after
Diagnose/debug with it by separating insufficient heap allocation from memory leaks and choosing temporary or sustainable remedies.
How it connects
Connects -Xmx with JVM heap, garbage collection, memory leaks, OutOfMemoryError, heap dumps, and -Xms.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Troubleshooting Java, Second Edition. The section links point to the parts of the book it draws on.