memory-leak-debug

Diagnose Node.js memory leaks using heap snapshots and chrome-devtools CLI analysis.

27.5k|3.0k|Updated Jun 26, 2025
One-click install
npx skills add https://github.com/QwenLM/qwen-code --skill memory-leak-debug
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: memory-leak-debug
Source: https://github.com/QwenLM/qwen-code/tree/main/.qwen/skills/memory-leak-debug
Command: npx skills add https://github.com/QwenLM/qwen-code --skill memory-leak-debug

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires chrome-devtools-mcp, and includes scripts (resource) components.

What problem does it solve?

Tracking down memory leaks in a Node.js CLI application is difficult without a repeatable workflow: heap grows silently, and identifying which objects are retained and why requires specialized tooling. This Skill provides a step-by-step procedure to capture heap snapshots from the Qwen Code CLI and analyze retained objects to pinpoint the leak's root cause.

Core Features & Use Cases

  • Heap Snapshot Capture: Launch the CLI with --heapsnapshot-signal=SIGUSR2 inside tmux and trigger snapshots at intervals with kill -USR2 to compare memory growth over time.
  • Retained Object Analysis: Use the chrome-devtools CLI to load snapshots, get class-level aggregates with retained sizes, inspect leaking instances, and trace retainer chains to the root retention path.
  • Fix Verification Workflow: Re-run the same workload after a fix and confirm the leaking class count stabilizes instead of growing with activity.
  • Use Case: After an ink 7 upgrade caused ~143 MB of PerformanceMeasure object retention, this workflow traced the leak to react-reconciler's dev build calling performance.measure() on every render, fixed by setting NODE_ENV=production in the esbuild config.

Quick Start

Ask the agent to diagnose high memory usage in the Qwen Code CLI by capturing heap snapshots and analyzing them with the chrome-devtools CLI.

Frequently Asked Questions about memory-leak-debug

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I capture a heap snapshot from a running Node.js process?▼

Start Node.js with the --heapsnapshot-signal=SIGUSR2 flag, then send kill -USR2 to the process PID at intervals. Snapshots are written to the working directory as Heap.<timestamp>.<pid>.<seq>.heapsnapshot files.

How do I find which objects are leaking in a heap snapshot?▼

Load the snapshot with chrome-devtools load_memory_snapshot, then run get_memory_snapshot_details to get class-level counts and retained sizes. Compare across snapshots to find classes whose count grows unboundedly, then trace retainer chains with get_node_retainers.

What tools are required for Node.js memory leak debugging with this workflow?▼

You need Node.js 22+ for heapsnapshot signal support, tmux to drive the CLI and trigger snapshots from another pane, and the chrome-devtools CLI from the chrome-devtools-mcp package for offline snapshot analysis.

Why does my Node.js heap keep growing during normal CLI usage?▼

Common causes include unbounded arrays or buffers without eviction, event listeners registered on long-lived emitters, closures capturing large objects, and module-level Map or Set caches. Comparing class aggregates across snapshots reveals which pattern applies.

Can I analyze heap snapshots without connecting to a live Node process?▼

Yes. Start the chrome-devtools daemon with chrome-devtools start --experimentalMemory --headless, which runs in file-analysis mode. All memory tools operate directly on .heapsnapshot files without a browser or live connection.