Search code examples
node.jsherokusocket.iomemory-leaks

Heroku NodeJS heap size different in reporting and Chrome Memory Debugger


I have a Heroku app running that is exhibiting memory leak behavior. Memory usage shown here:

enter image description here

As the leak occurs only in production (and requires users to take a few steps), I decided to SSH into Heroku app/enable tunneling to connect via Chrome DevTools. However, the Memory profiler tells me the JS Heap is ~70-90mbs consistently while Heroku reports it climbing to ~750mbs.

enter image description here

Anyone have any idea why this discrepancy? Is the Chrome Debugger wrong? Is Heroku showing me more than heap? Unclear how to proceed as I can't currently find the leak in any dev tool. Thanks!


Solution

  • Ended up doing a lot of reading into Node memory/heap management, garbage collection, the various types of memory. Realizing now that heap staying the same meant memory was allocating elsewhere in the stack. In my case, it was due to the use of Buffer in the 'pdf-lib' PDF library.

    Buffers are not counted in heap, but rather in dedicated Buffer memory. Hope this helps someone!