Uncovering Hidden Leaks: Native Memory Tracking

Employ `-XX:NativeMemoryTracking=summary` or `=detail` to gain visibility into off-heap memory usage, which is crucial for diagnosing memory leaks in ML applications that heavily rely on direct byte buffers or native libraries, as these are invisible to standard heap analysis tools.

The top 3

  1. Top 3 `jcmd` Commands for NMT Diagnostics: Effectively diagnosing native memory leaks with NMT often relies on three key `jcmd` commands: `VM.native_memory summary` for overall category-based usage, `VM.native_memory baseline` to establish a snapshot, and `VM.native_memory summary.diff` or `detail.diff` to pinpoint memory growth since the baseline.
  2. Top 3 Hidden Native Memory Leak Culprits: Common sources of hard-to-find native memory leaks include excessive use or improper management of Direct ByteBuffers, memory allocated via Java Native Interface (JNI) calls that isn't freed, and uncontrolled Metaspace growth from dynamic class loading.
  3. NMT Overhead: Summary vs. Detail Performance Impact: Native Memory Tracking (NMT) has different performance implications based on its mode: `off` has no overhead, `summary` offers low overhead by tracking bytes per category, while `detail` provides call site information but can introduce a 5-10% JVM performance drop and add 16 bytes per malloc.

Sources

Open the full topic