- Home
- Skills
- Testing & Debugging
- Node.js Memory Leak Finder with Heap Snapshots
Works with the AI Agents you already use
Node.js Memory Leak Finder with Heap Snapshots
Find why Node.js memory keeps climbing: three-snapshot heap diff, retainer path to file:line, smallest fix, before/after soak proof. Verdict STABLE / GROWING / LEAKING.
$7
Node.js Memory Leak Finder with Heap Snapshots
Example session with this skill installed
Our NestJS API gets OOMKilled roughly every 4 hours in Kubernetes (512Mi limit). Memory climbs steadily under normal traffic. Find the leak, fix it, and prove the fix. Use the staging pod, not prod.
- Read your context and instructions
- Compiled the node js memory
Memory leak report: orders-api (2026-10-19)
Verdict: LEAKING (fixed on branch fix/session-cache-leak, proof below)
Environment: Node 22, NestJS 11, staging pod taken out of the load balancer. Snapshots via --heapsnapshot-signal=SIGUSR2, deleted after analysis: yes
Symptom
- heapUsed after forced GC rises every round; RSS follows it (measured). external/arrayBuffers flat, so this is a JS heap leak, not Buffers.
Reproduction
autocannon, 3 rounds x 5,000 requests to GET /orders, 60 s idle between rounds, global.gc() before each sample.
| Round | heapUsed after GC |
|---|---|
| warm-up | 92 MB |
| 1 | 118 MB |
| 2 | 145 MB |
| 3 | 171 MB |
Retainer chain (snapshot C vs B, sorted by # Delta)
(GC root) -> Module src/auth/session.service.ts -> const sessionCache (Map) -> +5,000 entries -> Session -> user, permissions, req.headers
The +5,000 delta matches the 5,000 requests sent in the round.
Root cause
src/auth/session.service.ts:14 caches every decoded session in a module-level Map keyed by request id, never by user, with no max size or TTL. Entries are never deleted.
Fix (smallest change)
import { LRUCache } from 'lru-cache';
const sessionCache = new LRUCache<string, Session>({ max: 10_000, ttl: 5 * 60_000 });
// key by userId + token hash instead of request id
Proof (same load, same pod)
| Round | Before fix | After fix |
|---|---|---|
| 1 | 118 MB | 97 MB |
| 2 | 145 MB | 98 MB |
| 3 | 171 MB | 98 MB |
2-hour soak after fix: post-GC heap flat at 96-101 MB (measured).
Guardrails
test/memory/session-cache.spec.ts: 20,000 iterations, asserts post-GC heap growth < 10 MB- Alert on 1-hour slope of post-GC heap > 5 MB/h
Next steps
- Merge the fix and remove the temporary memory logger.
- Keep the 512Mi limit; with
--max-old-space-size=384there is headroom for off-heap memory.
Connects securely to your tools. The creator never sees your data.
About this skill
Your Node.js service creeps up in memory until the pod is OOMKilled or the process dies with "JavaScript heap out of memory". Restarting it every few hours hides the problem, and raising --max-old-space-size just delays it. Asking an AI to "find the leak" usually gets a list of generic suspects with no proof.
This skill gives your coding agent a disciplined, measurement-first procedure plus two reference files (a heap cheatsheet and 13 common leak patterns). It:
- Classifies the symptom first: JS heap leak, off-heap/Buffer growth (RSS up, heap flat), or a normal GC sawtooth that is not a leak at all
- Reproduces the growth under controlled load with a temporary memory logger and forced GC, so the numbers mean something
- Runs the three-snapshot technique (warm-up, A, B, C) using DevTools, --heapsnapshot-signal, v8.writeHeapSnapshot() or --heapsnapshot-near-heap-limit
- Reads the retainer chain from GC root to the leaking object and writes it into the report
- Matches it to known patterns: unbounded caches, per-request listeners, uncleared timers, never-settling promises, per-request DB/HTTP clients, AsyncLocalStorage retention, unconsumed fetch bodies
- Applies the smallest fix (bounded LRU, removed listener, hoisted client) and proves it with the same load: post-GC heap per round, before vs after
- Adds a regression guard (heap-growth test or post-GC slope alert)
- Gives a verdict: STABLE, GROWING or LEAKING
Works with Express, Fastify, NestJS, Koa, Next.js server code, workers and queues.
Safety and honesty: heap snapshots contain live data, so the skill treats them as secrets, keeps them out of git and deletes them afterwards. It asks before running load against shared environments, avoids snapshotting production instances that are serving traffic, never invents object counts or memory numbers, and labels every figure measured or estimate. Raising memory limits or scheduled restarts are offered only as clearly labelled temporary mitigations, never as the fix.
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Testing & Debugging.
Needs a reproducible way to trigger the growth (load script or job run). Heap snapshots pause the process and need disk space of roughly 1-3x the heap. Native addon leaks can be located but may require an upstream fix. Serverless functions with very short lifetimes are better diagnosed locally.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Money-back guarantee
Doesn't do what its page promises? You get your money back.
Trust & safety
Security scan
Security scan passed 28 days ago
- Software
Node.js
Chrome DevToolsorV8 heap viewerautocannonork6
Any V8 heap snapshot viewer works. autocannon or k6 generates the load.