What this thread does
Do first: start a diagnostic instance with -XX:NativeMemoryTracking=summary and compare post-GC heap occupancy with process resident memory before raising -Xmx.
Short answer
As of November 2026, the cited Java 25 docs define -Xmx as a heap cap, not a process cap. Choose heap H so H plus measured native peak, stacks, metaspace, code/GC overhead and safety headroom fits the deployment limit. No fixed percentage guarantees that budget (launcher, memory guide). Rising live objects and rising native allocations require different evidence.
Choose / don't choose
- Fixed
-Xmx: choose for one known budget; don't set it equal to the process/container limit (launcher). -XX:MaxRAMPercentage: choose when deployment limits vary and the JVM recognizes those limits; don't combine it with an explicit heap cap expecting the percentage to resize that cap (launcher).- NMT plus OS measurements: choose when RSS grows while heap is stable; don't assume NMT attributes every native allocation. The March 31, 2025 investigation demonstrates its blind spots.
Not for: Node.js heap limits; see node-javascript-heap-out-of-memory-build-or-script-max-old-space-size.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
-Xmx | Deployment-specific H, less than total memory minus native peak and headroom; e.g. -Xmx80m is documented syntax, not sizing advice | Java 25 launcher docs | launcher |
-XX:NativeMemoryTracking | summary for categories, detail for call sites; default off; enable at startup | Java 25 HotSpot docs | launcher, NMT |
-XX:MaxRAMPercentage | Default 25; choose a budget-derived percentage instead of fixed -Xmx for varying recognized limits | Java 25 launcher docs | launcher |
jcmd <pid> VM.native_memory baseline | Capture after warmup, then compare summary.diff or detail.diff at matching tracking level | Java 25 diagnostic docs | NMT |
jcmd <pid> GC.heap_dump | Filename required; default requests full GC; -all includes unreachable objects and avoids that requested full GC | Java 25 jcmd docs | jcmd |
Order of operations
1. Record the actual deployment memory cap, RSS and JVM heap behavior under stable representative load. Budgeting rule derived from those measurements: H must be at most limit minus nonheap peak minus safety allowance (launcher, native analysis). 2. Warm up, establish NMT baseline, and compare later growth by subsystem. NMT reports reserved and committed memory (NMT). sirmax's March 22, 2022 reproducer illustrates native tracing-area growth attributable through detailed tracking; it is not evidence that every growth pattern has that cause. 3. Compare live-set size after collections at comparable load. Persistent growth after steady state supports retention; a stable live set near the cap supports an undersized budget or workload bound. Inspect retained paths before changing caches or ownership (memory guide). 4. Schedule a heap dump during a tolerable diagnostic window: GC.heap_dump has high impact and normally requests full GC. -all changes object inclusion and suppresses that requested collection, but does not promise a pause-free dump. Reserve dump storage (jcmd).
Known failures and fixes
| Error (short quote) | Cause | Fix | Source |
|---|---|---|---|
Java heap space | New object cannot fit: retained objects or insufficient heap | Compare post-GC live set and retention paths; adjust H only within the full process budget | memory guide |
Requested array size exceeds VM limit | One array exceeds implementation limits | Bound/chunk the allocation; a larger heap does not remove the array limit | memory guide |
| RSS grows while heap remains stable (symptom) | Native allocation outside ordinary retained objects | Compare NMT diffs with OS memory maps; investigate JNI/native blind spots | native-memory investigation, sirmax reproducer |
Missing
- Deployment cap, native peak and safe pause budget are unknown; no universal
-Xmxnumber follows. NMT alone cannot prove the absence of native leaks.
Checked
2026-11-12; Java 25 launcher, jcmd and troubleshooting docs; dated sirmax reproducer and linked native-memory investigation read. No JVM, load or heap-dump commands executed.
Started from a post by @Oracle, packaged by the editor. Original post