memory-leaks

memory-leaks is a skill for Claude Code, Codex from cass-2003/local-workflow-skill. It costs 163 tokens per session (3,283 once invoked), scanned A, original, MIT.

A guide to finding memory leaks in applications and services. A memory leak is memory that a program keeps using even when it no longer needs it.

In plain words
What is it for?
Use it to compare heap snapshots, inspect memory growth, investigate out-of-memory kills, and find leaks caused by caches, listeners, timers, closures, or global references.
Why use it?
It helps explain why a process, browser tab, or container keeps growing until it becomes slow or runs out of memory.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it to compare heap snapshots, inspect memory growth, investigate out-of-memory kills, and find leaks caused by caches, listeners, timers, closures, or global references.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/cass-2003/local-workflow-skill/memory-leaks
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add cass-2003/local-workflow-skill --skill memory-leaks
Clone the repo
git clone --depth 1 https://github.com/cass-2003/local-workflow-skill

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for memory-leaks

README.md
[![agentmods](https://agentmods.dev/badge/skills/cass-2003/local-workflow-skill/memory-leaks/github.svg)](https://agentmods.dev/skills/cass-2003/local-workflow-skill/memory-leaks)
Your own site
<a href="https://agentmods.dev/skills/cass-2003/local-workflow-skill/memory-leaks"><img src="https://agentmods.dev/badge/skills/cass-2003/local-workflow-skill/memory-leaks/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for memory-leaks

Your own site · 80×15
<a href="https://agentmods.dev/skills/cass-2003/local-workflow-skill/memory-leaks"><img src="https://agentmods.dev/badge/skills/cass-2003/local-workflow-skill/memory-leaks.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 163 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 3,283 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 1 finding. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00163 $0.03283
Opus 5.5 $0.00065 $0.01313
Sonnet 5.5 $0.00033 $0.00657
Haiku 4.5 $0.00016 $0.00328

Measured 3mo ago against content hash d1e804e13f10, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

memory-leaks scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Makes network callslowCapability

Not a fault in itself. Listed so you know the mod talks to something, and to what.

if (!cache.has(key)) cache.set(key, fetch(key))
skills/engineering-core/ours/memory-leaks/SKILL.md · 405 lines

How it starts

The opening of the file, as written. The whole thing — 405 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Memory Leaks Skill — 内存泄漏排查

何时使用

  • 服务跑久了内存爆 / OOMKilled
  • Chrome 页面用一会卡顿 / 标签页崩溃
  • 容器 RSS 持续增长不释放
  • 单元测试通过但生产泄漏
  • 怀疑某个改动引入泄漏

一、判断真泄漏 vs 假象

真泄漏:内存 monotonic 增长,永不下降,最终 OOM
   → 引用链让 GC 无法回收

假象:
  - 工作集大但稳定(cache 满了)→ 不是泄漏
  - 临时峰值(处理大请求)→ 不是泄漏
  - V8 / GC 延迟回收 → 等几分钟看是否下降

最可靠诊断:长时间观察 RSS 曲线。

# 容器
docker stats <container>
kubectl top pod <pod>

# 进程
ps aux | grep app
top -p <pid>

观察 趋势,不是瞬时值。

二、Node.js 内存模型

RSS = Resident Set Size(OS 视角,进程占的物理内存)
     = V8 heap + native heap + libuv buffers + ...

V8 heap = JS 对象(GC 管)
  - new space (young generation)
  - old space (long-lived)
  - large object space

外部缓冲区 = Buffer / ArrayBuffer
原生模块内存 = N-API addon 自管
console.log(process.memoryUsage())
// { rss, heapTotal, heapUsed, external, arrayBuffers }

三、Node 三快照对比法(黄金流程)

1. 服务启动 + 跑一会 → snapshot 1(baseline)
2. 触发可疑操作 N 次
3. 强制 GC → snapshot 2
4. 再触发 N 次 → snapshot 3
5. 对比 snapshot 2 → snapshot 3:净增长就是泄漏
// 启动允许 inspect 和 expose-gc
node --inspect --expose-gc app.js

// 代码或 console:
global.gc()
require('v8').writeHeapSnapshot('./snap-1.heapsnapshot')

Chrome → chrome://inspect → "Memory" → "Load profile" → Comparison view。

Comparison 看什么:

  • "Delta" 列正数 = 增加的对象
  • 按 retained size 排序
  • 点对象看 Retainers(谁持有它,回溯到 GC root)

四、Node 常见泄漏模式

1. 闭包持有大对象

// ❌ 整个 huge 被闭包捕获
function makeHandler(huge) {
  return () => console.log('hi')   // 没用 huge 但仍引用作用域
}

// ✅ 显式提取需要的
function makeHandler(huge) {
  const id = huge.id   // 只引用 id
  return () => console.log(id)
}

2. EventEmitter 监听器累积

// ❌ 每次 add 都加,never remove
emitter.on('data', handler)
// 1000 次 emitter.on 后,1000 个 handler 引用 closure

// ✅ 用 once 或显式 off
emitter.once('data', handler)
emitter.off('data', handler)
emitter.removeAllListeners('data')

// 检测
emitter.setMaxListeners(20)   // 超出告警
emitter.listenerCount('data')

3. setInterval 不清

// ❌
const t = setInterval(() => doStuff(largeObj), 1000)
// largeObj 被 closure 抓住直到 clearInterval

// ✅
const t = setInterval(...)
on('shutdown', () => clearInterval(t))

// Node-specific:让 timer 不阻止退出
t.unref()

Read the full file on GitHub · 405 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3mo ago First seen · 405 lines · 163 tokens per session scan A d1e804e13f10

Subscribe to this mod's changes

memory-leaks is a skill published in the GitHub repository cass-2003/local-workflow-skill (12 stars, last pushed 4mo ago), licensed MIT. It adds 163 tokens to every session and 3,283 once invoked, about $0.0007 per session on Opus 5.5. A static security scan graded it A with 1 finding (makes network calls). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.

Related

memory-leaks compared with skills from other repositories

memory-leaks next to 6 skills from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
memory-leakscass-2003/local-workflow-skillSkill124mo agoMITA163Claude Code, Codex
systematic-debuggingopen-metadata/OpenMetadataSkill16ktodayApache-2.0A37Claude Code
log-error-digestzebbern/claude-code-guideSkill4.7ktodayMITA71Claude Code, Codex
observability-audit-sessionsIBM/mcp-context-forgeSkill4.9ktodayApache-2.0A64Claude Code, Codex
cwv-optimizeradobe/skillsSkill343todayApache-2.0A112Claude Code
performance-verificationvalkor-ai/loomSkill1.6k2d agoApache-2.0A45Claude Code, Codex
loop-engineeringhuytieu/COG-second-brainSkill1.6ktodayMITA63Claude Code