The pattern is familiar. Memory climbs slowly for a day or three, then a pod restarts with OOMKilled , or the process dies with FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory . The restart brings memory back down, so the graph looks like a saw with very long teeth. And it never happens on your machine, because nothing on your machine runs for three days under real traffic.
Restarts hide a leak, they don't fix it. Here's how I'd go from "memory keeps growing" to the line of code that holds on to it.
First: is it actually a leak?
Node's memory always moves. V8 allocates, collects, allocates again, so a healthy service draws a sawtooth. A leak is when the bottom of the sawtooth keeps rising: what survives each major garbage collection grows, while traffic stays flat.
Three numbers from process.memoryUsage() tell most of the story:
heapUsed : memory held by live JavaScript objects. A leak in your code shows up here.
heapTotal : what V8 has reserved for the heap.…