NMT: First Line for JNI Memory Growth

The JVM's Native Memory Tracking (`-XX:NativeMemoryTracking=summary|detail`) provides categorized breakdowns of native memory usage, quickly highlighting if the JNI category is experiencing significant, unexplained growth indicative of leaks.

The top 3

  1. NMT's Direct View: JNI Memory Categories: Native Memory Tracking (NMT) explicitly provides a 'JNI' category in its reports, detailing reserved and committed memory to specifically track allocations related to Java Native Interface usage managed by the JVM.
  2. Spotting JNI Leaks: NMT Trend Analysis: To identify JNI global reference leaks using NMT, monitor for a consistent, unchecked increase in the 'JNI' category's committed memory over time, typically by comparing `VM.native_memory baseline` and `VM.native_memory diff` reports.
  3. Beyond NMT: Native Code JNI Leak Blind Spots: NMT primarily tracks JVM-internal allocations and cannot directly trace memory allocated by native libraries using `malloc` or `new` within JNI code; if overall process RSS grows but NMT's JNI category remains stable, a leak in the native library itself is likely, requiring OS-level tools for diagnosis.

Sources

Open the full topic