memory-leak-detection▌
aj-geddes/useful-ai-prompts · updated Apr 8, 2026
Identify and fix memory leaks to prevent out-of-memory crashes and optimize application performance.
Memory Leak Detection
Table of Contents
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:
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 | Node.js Heap Snapshots |
| Memory Leak Detection Middleware | Memory Leak Detection Middleware |
| Common Memory Leak Patterns | Common Memory Leak Patterns |
| Python Memory Profiling | Python Memory Profiling |
| WeakMap/WeakRef for Cache | WeakMap/WeakRef for Cache |
| Memory Monitoring in Production | 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
Discussion
Product Hunt–style comments (not star reviews)- No comments yet — start the thread.
Ratings
4.6★★★★★61 reviews- ★★★★★Harper Reddy· Dec 12, 2024
Useful defaults in memory-leak-detection — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.
- ★★★★★Chen Sharma· Dec 12, 2024
memory-leak-detection has been reliable in day-to-day use. Documentation quality is above average for community skills.
- ★★★★★Chen Shah· Dec 8, 2024
I recommend memory-leak-detection for anyone iterating fast on agent tooling; clear intent and a small, reviewable surface area.
- ★★★★★Michael Thompson· Dec 4, 2024
memory-leak-detection is among the better-maintained entries we tried; worth keeping pinned for repeat workflows.
- ★★★★★Kiara Thomas· Nov 27, 2024
Keeps context tight: memory-leak-detection is the kind of skill you can hand to a new teammate without a long onboarding doc.
- ★★★★★Kaira Rahman· Nov 3, 2024
We added memory-leak-detection from the explainx registry; install was straightforward and the SKILL.md answered most questions upfront.
- ★★★★★Nia Agarwal· Nov 3, 2024
Solid pick for teams standardizing on skills: memory-leak-detection is focused, and the summary matches what you get after install.
- ★★★★★Harper Torres· Oct 22, 2024
Solid pick for teams standardizing on skills: memory-leak-detection is focused, and the summary matches what you get after install.
- ★★★★★Kofi Ndlovu· Oct 22, 2024
We added memory-leak-detection from the explainx registry; install was straightforward and the SKILL.md answered most questions upfront.
- ★★★★★Olivia Sharma· Oct 18, 2024
Registry listing for memory-leak-detection matched our evaluation — installs cleanly and behaves as described in the markdown.
showing 1-10 of 61