Memory Leak Detection

Memory Leak Detection

Helps an AI agent detect and fix memory leaks with heap snapshots, profiling in Node.js and Python, and production memory monitoring.

Skill files9 files

references/

scripts/

templates/

SKILL.md96 lines
1
---
2
name: memory-leak-detection
3
description: >
4
Detect and fix memory leaks using heap snapshots, memory profiling, and leak
5
detection tools. Use when investigating memory growth, OOM errors, or
6
optimizing memory usage.
7
---
8
9
# Memory Leak Detection
10
11
## Table of Contents
12
13
- [Overview](#overview)
14
- [When to Use](#when-to-use)
15
- [Quick Start](#quick-start)
16
- [Reference Guides](#reference-guides)
17
- [Best Practices](#best-practices)
18
19
## Overview
20
21
Identify and fix memory leaks to prevent out-of-memory crashes and optimize application performance.
22
23
## When to Use
24
25
- Memory usage growing over time
26
- Out of memory (OOM) errors
27
- Performance degradation
28
- Container restarts
29
- High memory consumption
30
31
## Quick Start
32
33
Minimal working example:
34
35
```typescript
36
import v8 from "v8";
37
import fs from "fs";
38
39
class MemoryProfiler {
40
takeSnapshot(filename: string): void {
41
const snapshot = v8.writeHeapSnapshot(filename);
42
console.log(`Heap snapshot saved to ${snapshot}`);
43
}
44
45
getMemoryUsage(): NodeJS.MemoryUsage {
46
return process.memoryUsage();
47
}
48
49
formatMemory(bytes: number): string {
50
return `${(bytes / 1024 / 1024).toFixed(2)} MB`;
51
}
52
53
printMemoryUsage(): void {
54
const usage = this.getMemoryUsage();
55
56
console.log("Memory Usage:");
57
console.log(` RSS: ${this.formatMemory(usage.rss)}`);
58
console.log(` Heap Total: ${this.formatMemory(usage.heapTotal)}`);
59
console.log(` Heap Used: ${this.formatMemory(usage.heapUsed)}`);
60
console.log(` External: ${this.formatMemory(usage.external)}`);
61
// ... (see reference guides for full implementation)
62
```
63
64
## Reference Guides
65
66
Detailed implementations in the `references/` directory:
67
68
| Guide | Contents |
69
|---|---|
70
| [Node.js Heap Snapshots](references/nodejs-heap-snapshots.md) | Node.js Heap Snapshots |
71
| [Memory Leak Detection Middleware](references/memory-leak-detection-middleware.md) | Memory Leak Detection Middleware |
72
| [Common Memory Leak Patterns](references/common-memory-leak-patterns.md) | Common Memory Leak Patterns |
73
| [Python Memory Profiling](references/python-memory-profiling.md) | Python Memory Profiling |
74
| [WeakMap/WeakRef for Cache](references/weakmapweakref-for-cache.md) | WeakMap/WeakRef for Cache |
75
| [Memory Monitoring in Production](references/memory-monitoring-in-production.md) | Memory Monitoring in Production |
76
77
## Best Practices
78
79
### ✅ DO
80
81
- Remove event listeners when done
82
- Clear timers and intervals
83
- Use WeakMap/WeakRef for caches
84
- Limit cache sizes
85
- Monitor memory in production
86
- Profile regularly
87
- Clean up after tests
88
89
### ❌ DON'T
90
91
- Create circular references
92
- Hold references to large objects unnecessarily
93
- Forget to clean up resources
94
- Ignore memory growth
95
- Skip WeakMap for object caches
96

© AJ Geddes · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 14,621 prompts

More by @OpenSourceBuffGuy

See all
Sea turtle carrying floating film studio island prompt image

Sea turtle carrying floating film studio island

Draws a giant sea turtle carrying a floating island film studio through a starry sky, where fairies polish rough film strips into golden film.

image-prompt, nano-banana, 3d-render, cartoon, fantasy-world, creatures, animals, whimsical, dreamy, cinematic, dramatic-lighting, vibrant-colors, bokeh, miniature, widescreen, night-scene, illustration, concept-art, surreal, storytelling, clay-3d

Desert buggy escapes drones past industrial outpost prompt image

Desert buggy escapes drones past industrial outpost

Builds a 15-second desert chase video where a racer in an armored buggy escapes drones past an industrial outpost, using five reference images with set jobs.

video-prompt, hailuo, action, multi-shot, timed-beats, camera-movement, reference-image, character-consistency, negative-prompt, cinematic, sci-fi, cars, landscape, aerial-view, tracking-shot, photorealistic, sound-effects, structured-output, long-form, widescreen

1 view
Cozy Pixel Art Farm Island Village prompt image

Cozy Pixel Art Farm Island Village

Draws a cozy 16-bit pixel-art farming village across six small islands joined by bridges, with exact counts for buildings, animals and crops.

image-prompt, gpt-image, pixel-art, isometric, game-assets, concept-art, maps, worldbuilding, cozy, vibrant-colors, ocean, landscape, wide-shot, widescreen, game-development, video-games, structured-output, whimsical, summer, high-angle, aerial-view, animals, negative-prompt, cityscape

1 view

Reviews

Loading reviews…

Discussion

Loading comments…