I have a lot of "not very well" written JavaScript scripts I run in nodejs environment. It contains memory leaks, infinite loops and whatever code can "regular" (non-programmers) user produce.
What I found out when randomly analyzing execution of those "scripts" was, that some of them has huge rss
memory area lets say around 1.0GB while heapTotal
might be "just" around 450MB.
Despite reading blog posts about memory layout in nodejs I am not able to explain/simulate such "leak". I tried to create heapdump but obviously I wont find what is stored in the "stack area" because I did not dump that zone.
Do anyone know what has to happen in the source code so we leak out all memory while heap size is much smaller i.e. what would "evil source code" look like to eat space out of heap?
EDIT:
I found out that its pretty simple: const c = Buffer.alloc(1024*1024*1024, 1)
consumes 1GB outside of heap. New question arise: How can one "clean out" this space and free the memory up? How can I detect leaky buffers? Is restart only way?