Node.js Memory Leaks from Frequent Allocations? glibc Mechanism and Fixes

_jzhao · x · 2026-07-31

The author points out a weird behavior in glibc where free() does not return memory for interior free chunks back to the OS. Because Node.js, libuv, and V8 never call malloctrim(0) to fix this, Node applications that allocate and recycle Buffers really frequently can cause memory to leak.

A workaround is provided using an LDPRELOAD library and configuring the MALLOCCONF environment variable (e.g., setting dirtydecayms).

Original post →

More from coding & agent

coding & agent channel →