memory-leak-detection — скилл для Claude Code: поиск утечек памяти
Скилл помогает найти и починить утечки памяти: heap-снимки, профилирование, разбор типичных причин роста потребления.
npx skills add aj-geddes/useful-ai-prompts --skill memory-leak-detection -a claude-codeЧто делает memory-leak-detection
Скилл разбирает утечки памяти по шагам: снимает heap-снимки через v8.writeHeapSnapshot, читает process.memoryUsage() и показывает RSS, heap total, heap used и external в мегабайтах. Внутри есть готовый класс MemoryProfiler на TypeScript — можно взять как основу для своего кода.
Кроме быстрого примера в скилле лежат справочники в каталоге references/: heap-снимки в Node.js, middleware для отслеживания утечек, частые паттерны утечек, профилирование памяти в Python, кэш на WeakMap и WeakRef, мониторинг памяти в продакшене. Отдельный раздел с практиками: снимать слушатели событий, чистить таймеры и интервалы, ограничивать размер кэша, профилировать регулярно.
Скилл пригодится, когда память растёт со временем, контейнер перезапускается или приложение падает с OOM. Обратная сторона тоже описана: циклические ссылки, лишние ссылки на большие объекты и забытая очистка ресурсов — как раз то, из-за чего утечка и появляется.
Какие задачи решает
- найти причину роста потребления памяти в Node.js-сервисе
- разобрать heap-снимок и понять, что держит объекты
- починить утечку из-за незакрытых слушателей событий
- заменить обычный кэш на WeakMap и ограничить его размер
- настроить мониторинг памяти в продакшене
Примеры запросов агенту
- сними heap-снимок и покажи, что растёт в памяти
- найди утечку в этом сервисе Node.js
- проверь, не держат ли таймеры и слушатели лишние ссылки
Как установить memory-leak-detection
1Через Skills CLI (Vercel)
npx skills add aj-geddes/useful-ai-prompts --skill memory-leak-detection -a claude-code2Вручную: положить файлы
~/.claude/skills/memory-leak-detection/SKILL.mdПапка скилла целиком; для одного проекта — .claude/skills/memory-leak-detection/
1Через Skills CLI (Vercel)
npx skills add aj-geddes/useful-ai-prompts --skill memory-leak-detection -a codex2Вручную: положить файлы
.agents/skills/memory-leak-detection/SKILL.mdДля всех проектов — ~/.agents/skills/
1Через Skills CLI (Vercel)
npx skills add aj-geddes/useful-ai-prompts --skill memory-leak-detection -a cursor2Вручную: положить файлы
.cursor/skills/memory-leak-detection/SKILL.mdCursor читает и .agents/skills/, и .claude/skills/
1GitHub CLI
gh skill install aj-geddes/useful-ai-prompts memory-leak-detection2Вручную: положить файлы
.github/skills/memory-leak-detection/SKILL.md1Через Skills CLI (Vercel)
npx skills add aj-geddes/useful-ai-prompts --skill memory-leak-detection -a gemini-cli2Командой платформы
gemini skills install https://github.com/aj-geddes/useful-ai-prompts --path skills/memory-leak-detectionВручную: положить файлы
.devin/skills/memory-leak-detection/SKILL.mdСтарый путь .windsurf/skills/ тоже читается
Через Skills CLI (Vercel)
npx skills add aj-geddes/useful-ai-prompts --skill memory-leak-detection -a opencodeClaude.ai
Упакуйте папку в zip и загрузите в Settings → Capabilities → Skills
По шагам, с командами для каждой платформы: Как установить скилл в Claude Code: пять способов
Из того же набора118
Похожие
Рядом в теме «Бэкенд и API»
Всё по теме «Бэкенд и API» →Вопросы о memory-leak-detection
Как установить memory-leak-detection в Claude?
Выполните npx skills add aj-geddes/useful-ai-prompts --skill memory-leak-detection -a claude-code. После установки файл скилла лежит в ~/.claude/skills/memory-leak-detection/SKILL.md.
Что делает memory-leak-detection?
Помогает искать и исправлять утечки памяти: heap-снимки, профилирование, разбор частых паттернов утечек и мониторинг памяти в продакшене.
Для каких платформ подходит скилл?
Кроме Claude есть установка для Codex, Cursor, GitHub Copilot, Gemini CLI и OpenCode — команды отличаются только флагом агента.
Исходный текст
SKILL.md · MIT
---
name: memory-leak-detection
description: >
Detect and fix memory leaks using heap snapshots, memory profiling, and leak
detection tools. Use when investigating memory growth, OOM errors, or
optimizing memory usage.
---
# Memory Leak Detection
## Table of Contents
- [Overview](#overview)
- [When to Use](#when-to-use)
- [Quick Start](#quick-start)
- [Reference Guides](#reference-guides)
- [Best Practices](#best-practices)
## Overview
Identify and fix memory leaks to prevent out-of-memory crashes and optimize application performance.
## When to Use
- Memory usage growing over time
- Out of memory (OOM) errors
- Performance degradation
- Container restarts
- High memory consumption
## Quick Start
Minimal working example:
```typescript
import v8 from "v8";
import fs from "fs";
class MemoryProfiler {
takeSnapshot(filename: string): void {
const snapshot = v8.writeHeapSnapshot(filename);
console.log(`Heap snapshot saved to ${snapshot}`);
}
getMemoryUsage(): NodeJS.MemoryUsage {
return process.memoryUsage();
}
formatMemory(bytes: number): string {
return `${(bytes / 1024 / 1024).toFixed(2)} MB`;
}
printMemoryUsage(): void {
const usage = this.getMemoryUsage();
console.log("Memory Usage:");
console.log(` RSS: ${this.formatMemory(usage.rss)}`);
console.log(` Heap Total: ${this.formatMemory(usage.heapTotal)}`);
console.log(` Heap Used: ${this.formatMemory(usage.heapUsed)}`);
console.log(` External: ${this.formatMemory(usage.external)}`);
// ... (see reference guides for full implementation)
```
## Reference Guides
Detailed implementations in the `references/` directory:
| Guide | Contents |
|---|---|
| [Node.js Heap Snapshots](references/nodejs-heap-snapshots.md) | Node.js Heap Snapshots |
| [Memory Leak Detection Middleware](references/memory-leak-detection-middleware.md) | Memory Leak Detection Middleware |
| [Common Memory Leak Patterns](references/common-memory-leak-patterns.md) | Common Memory Leak Patterns |
| [Python Memory Profiling](references/python-memory-profiling.md) | Python Memory Profiling |
| [WeakMap/WeakRef for Cache](references/weakmapweakref-for-cache.md) | WeakMap/WeakRef for Cache |
| [Memory Monitoring in Production](references/memory-monitoring-in-production.md) | Memory Monitoring in Production |
## Best Practices
### ✅ DO
- Remove event listeners when done
- Clear timers and intervals
- Use WeakMap/WeakRef for caches
- Limit cache sizes
- Monitor memory in production
- Profile regularly
- Clean up after tests
### ❌ DON'T
- Create circular references
- Hold references to large objects unnecessarily
- Forget to clean up resources
- Ignore memory growth
- Skip WeakMap for object caches
© aj-geddes · MIT · aj-geddes/useful-ai-prompts