Skip to main content
skill CX Codex

memory-leak-detection — Claude Code skill: find and fix leaks

A skill for tracking down memory leaks: heap snapshots, profiling and the usual patterns behind growing memory use.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add aj-geddes/useful-ai-prompts --skill memory-leak-detection -a claude-code
Open on GitHub

What memory-leak-detection does

The skill walks through leak hunting step by step. It takes heap snapshots with v8.writeHeapSnapshot, reads process.memoryUsage() and prints RSS, heap total, heap used and external in megabytes. A MemoryProfiler class in TypeScript ships as a starting point you can drop into your own code.

Beyond the quick example, the skill points to guides in the references/ directory: Node.js heap snapshots, leak detection middleware, common leak patterns, Python memory profiling, WeakMap and WeakRef caches, and memory monitoring in production. The practices section is blunt about cleanup — remove event listeners, clear timers and intervals, cap cache sizes, profile on a schedule.

Reach for it when memory climbs over time, containers keep restarting, or the process dies with an OOM error. The flip side is covered too: circular references, stray references to large objects and forgotten resource cleanup are exactly what causes the leak in the first place.

What it helps with

  • trace why memory keeps growing in a Node.js service
  • read a heap snapshot and find what still holds objects
  • fix a leak caused by event listeners that never get removed
  • swap a plain object cache for WeakMap and bound its size
  • set up memory monitoring in production

Example prompts for the agent

  • take a heap snapshot and show me what is growing
  • find the memory leak in this Node.js service
  • check whether timers or listeners are holding references

How to install memory-leak-detection

1Skills CLI (Vercel)

npx skills add aj-geddes/useful-ai-prompts --skill memory-leak-detection -a claude-code

2Manually: put the files in place

~/.claude/skills/memory-leak-detection/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/memory-leak-detection/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about memory-leak-detection

How do I install memory-leak-detection in Claude?

Run npx skills add aj-geddes/useful-ai-prompts --skill memory-leak-detection -a claude-code. The skill file then lives at ~/.claude/skills/memory-leak-detection/SKILL.md.

What does memory-leak-detection do?

It helps you detect and fix memory leaks using heap snapshots, memory profiling, common leak patterns and production memory monitoring.

Which platforms can run this skill?

Besides Claude, it installs for Codex, Cursor, GitHub Copilot, Gemini CLI and OpenCode — the commands differ only in the agent flag.

Source text

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

Similar skills

Everything for Backend and APIs →

From the same set118

design-patterns-implementation Guides the agent toward the right pattern for an architectural problem: Singleton, Factory, Observer, Strategy and more. Useful during refactoring or code review. CX Codex +1 595installs unit-testing-framework A skill that gives the agent rules for writing unit tests: Arrange-Act-Assert structure, mocks, edge cases. Useful when a function or class needs coverage. CX Codex +1 593installs database-query-optimization A skill that walks your agent through slow SQL: execution plans, indexes, and where the time actually goes. Useful when the database drags. CX Codex +1 586installs database-backup-restore A coding assistant skill for backup and disaster recovery strategies. Use it when planning backups, testing restore procedures, or setting up automated backup jobs. CX Codex +1 582installs technical-roadmap-planning Builds a technical roadmap across quarters and years: architecture, infrastructure, stack investments. Useful before a big modernization push. CX Codex +1 577installs accessibility-testing A skill that walks your agent through WCAG checks: axe scans, keyboard navigation, ARIA, screen readers. Useful when a project has to meet a11y requirements. CX Codex +1 575installs push-notification-setup Integrates push notifications for iOS and Android using Firebase Cloud Messaging and APNs. Helps handle token refreshes, deep linking, and background sync. CX Codex +1 575installs database-schema-documentation Documents database schemas, generates Mermaid ERD diagrams, and tracks table constraints. Useful when creating data dictionaries or writing migration specs. CX Codex +1 569installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor