Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIDeepSeekDeepSeekMuseMuse+22 more

    Node.js Memory Leak Finder with Heap Snapshots

    1

    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

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned
    Node.js Memory Leak Finder with Heap Snapshots

    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.

    RoundheapUsed after GC
    warm-up92 MB
    1118 MB
    2145 MB
    3171 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)

    RoundBefore fixAfter fix
    1118 MB97 MB
    2145 MB98 MB
    3171 MB98 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

    1. Merge the fix and remove the temporary memory logger.
    2. Keep the 512Mi limit; with --max-old-space-size=384 there 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. 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. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 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 DevTools
    orV8 heap viewer
    autocannon
    ork6

    Any V8 heap snapshot viewer works. autocannon or k6 generates the load.

    Permissions

    Terminal / Shell
    Read Files
    Write Files
    Listed28 days ago

    What's inside

    Frequently Asked Questions

    Any agent that supports the SKILL.md standard, including Claude Code, Codex CLI, Cursor, VS Code Copilot and Gemini CLI. The agent needs terminal access to run your service and a load tool.

    SKILL.md with the full diagnostic procedure and report format, plus two reference files: a heap and process.memoryUsage() cheatsheet, and a table of 13 common Node.js leak patterns with the matching fix.

    It measures before it guesses: reproduces growth with forced GC, compares three heap snapshots, and names the exact retainer chain before changing code. The fix is then proven with the same load, with every number labelled measured or estimate.

    It avoids snapshotting production instances that are serving traffic, because snapshots pause the process and contain live data. It prefers staging, a canary removed from the load balancer, or a local reproduction, asks before running load against shared environments, and deletes snapshot files after analysis.

    No. It uses Node's built-in flags and APIs, Chrome DevTools for snapshot comparison, and a free load tool such as autocannon or k6.

    It needs a way to reproduce the growth. Leaks inside native addons can be located but may need a library upgrade or upstream fix. Memory growth from allocator fragmentation is reported as GROWING with next diagnostics rather than presented as a code leak.

    New in Testing & Debugging