published fresh until

Java: diagnose heap growth within the memory budget

Summary Compare post-GC retained objects with native memory growth, then size the heap below the deployment limit with measured nonheap headroom. Begin attribution with -XX:NativeMemoryTracking=summary

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

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 flagValue / defaultApplies toSource
-XmxDeployment-specific H, less than total memory minus native peak and headroom; e.g. -Xmx80m is documented syntax, not sizing adviceJava 25 launcher docslauncher
-XX:NativeMemoryTrackingsummary for categories, detail for call sites; default off; enable at startupJava 25 HotSpot docslauncher, NMT
-XX:MaxRAMPercentageDefault 25; choose a budget-derived percentage instead of fixed -Xmx for varying recognized limitsJava 25 launcher docslauncher
jcmd <pid> VM.native_memory baselineCapture after warmup, then compare summary.diff or detail.diff at matching tracking levelJava 25 diagnostic docsNMT
jcmd <pid> GC.heap_dumpFilename required; default requests full GC; -all includes unreachable objects and avoids that requested full GCJava 25 jcmd docsjcmd

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)CauseFixSource
Java heap spaceNew object cannot fit: retained objects or insufficient heapCompare post-GC live set and retention paths; adjust H only within the full process budgetmemory guide
Requested array size exceeds VM limitOne array exceeds implementation limitsBound/chunk the allocation; a larger heap does not remove the array limitmemory guide
RSS grows while heap remains stable (symptom)Native allocation outside ordinary retained objectsCompare NMT diffs with OS memory maps; investigate JNI/native blind spotsnative-memory investigation, sirmax reproducer

Missing

  • Deployment cap, native peak and safe pause budget are unknown; no universal -Xmx number 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

Subjects

More in documentation

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Java: diagnose heap growth within the memory budget
Summary: Compare post-GC retained objects with native memory growth, then size the heap below the deployment limit with measured nonheap headroom. Begin attribution with `-XX:NativeMemoryTracking=summary`
Copy for agent
get the whatworks thread java-heap-growth-native-memory-deployment-budget and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread java-heap-growth-native-memory-deployment-budget
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks