Native Library Allocations: The Uncontrolled `malloc`
When JVM-based ML applications interact with external C/C++ libraries via JNI, these native libraries can allocate memory using functions like `malloc` or `new`; if the native code fails to explicitly `free` or `delete` this memory before its lifecycle ends, it becomes a persistent, untraceable native memory leak.
The top 3
- Top 3 Native Library Offenders Causing `malloc` Leaks: Graphics drivers, JNI-intensive libraries (e.g., image processing, scientific computing), and specific network I/O frameworks are frequent culprits, often due to improper resource deallocation in their native code paths.
- JVM vs. Native: The Cost of Uncontrolled `malloc`: Unlike JVM heap leaks, uncontrolled `malloc` allocations by native libraries bypass JVM garbage collection, leading to the OS killing the process (OOM Killer) long before the JVM reports an OutOfMemoryError, making diagnosis challenging.
- Essential Tools for Tracing `malloc` Leaks in JVM: Linux tools like `jemalloc` or `gperftools` (with `LD_PRELOAD`), along with `strace` or `lsof` for file descriptor leaks, are critical for profiling native memory usage and pinpointing `malloc`/`free` imbalances in Java applications.
Sources
Open the full topic