---
title: "Discussion on \"Hunting memory leaks in Node.js\" | Hashnode"
description: "Discussion on \"Hunting memory leaks in Node.js\". Story time\nSince a while, I've been stumbling upon cases with underlying memory leaks, analysing and fixing them. Most of the time the story starts with some alarm informing about increased memory usage for one of the services. After taking a closer ..."
url: "https://hashnode.com/posts/hunting-memory-leaks-in-nodejs/658ecd181369b22e2637ae5e"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Hunting memory leaks in Node.js](https://roertbb.hashnode.dev/hunting-memory-leaks-in-nodejs?utm_source=hashnode&utm_medium=feed)

Story time Since a while, I've been stumbling upon cases with underlying memory leaks, analysing and fixing them. Most of the time the story starts with some alarm informing about increased memory usage for one of the services. After taking a closer ...

Dec 29, 2023 · 10 min read · roertbb.hashnode.dev  
Read the article

-   [#nodejs](https://hashnode.com/tag/nodejs)
-   [#mongodb](https://hashnode.com/tag/mongodb)
-   [#mongoose](https://hashnode.com/tag/mongoose)
-   [#memory-management](https://hashnode.com/tag/memory-management)
-   [#memory-leak](https://hashnode.com/tag/memory-leak)
-   [#caching](https://hashnode.com/tag/caching)

## Written by

[Robert Banaszak](https://hashnode.com/@roertbb)

@roertbb · Poznań, Poland

  
[View profile](https://hashnode.com/@roertbb)

## Responses 1

Markdown supported · ⌘↵ to post

[Node Edge Ops](https://hashnode.com/@nodeedgeops)

[Nov 9](https://hashnode.com/posts/hunting-memory-leaks-in-nodejs/658ecd181369b22e2637ae5e/comment/6af2073bb86bec978a0610a0)

Hunt leaks with heap snapshots taken at steady state after warm-up, not right after process start. Diff two snapshots under the same load window and sort retainers by shallow size; watch for closures holding request-scoped objects, unbounded Maps keyed by connection id, and timers that never clear. Prefer short canary profiling with the built-in inspector so the profiler itself does not add GC noise that masks the leak. Reset suspect caches on a TTL while you iterate so each diff stays readable.

Ops prove-out: drive fixed QPS for several minutes, take snapshot A, continue, take snapshot B. Retained size of the suspect type should grow across A to B if the leak is real. Restart the process and confirm RSS returns; then reintroduce only the suspect path and watch the same growth. Clear the suspected cache on a TTL and verify the next diff flattens under identical traffic.
