I've been dealing with memory problems in my Express.js web app lately. It keeps crashing with the following error:
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap
out of memory
Initially, when I launch the service, the memory usage is around 170Mb (according to RES memory on htop). However, as I send requests to it, the memory consumption continues to grow.
I've been using memwatch
to track what seems like a memory leak, and a memwatch.HeapDiff()
shows something like this:
{ before: { nodes: 2093729, size_bytes: 197165296, size: '188.03 mb' },
after: { nodes: 2491264, size_bytes: 232097040, size: '221.34 mb' },
...
It indicates that the app is utilizing 221.34mb for the heap; however, htop reports about 2GB of memory usage when it crashes.
This brings me to the question: if my assumptions are correct, what could be consuming non-heap memory that is still shown as RES memory by htop?