| name | memory-management |
| description | Diagnose and resolve memory issues in production systems. Outputs heap analysis, leak detection strategies, GC tuning recommendations, and memory-efficient design patterns. |
| argument-hint | ["language/runtime","symptoms","heap size","GC type"] |
| allowed-tools | Read, Write, Bash |
Memory Management
Memory problems manifest as slow leaks, sudden OOM crashes, or GC pauses degrading latency. Fixing them requires understanding allocation patterns, retention paths, and the GC model of your runtime — not just restarting the process.
Process
- Confirm the symptom. Is it a slow leak, sudden OOM, high GC pause, or high steady-state usage? Each has different causes.
- Establish a baseline. Capture heap size, GC frequency, GC pause duration under normal load.
- Take a heap snapshot. Before and after a suspected leak period. Compare object counts and retained sizes.
- Find retention paths. What is holding a reference to the leaking objects? Walk the reference chain from GC roots.
- Fix the root cause. Don't tune GC as a substitute for fixing leaks.
- Tune GC last. After leaks are fixed, tune heap sizing and GC algorithm for your workload.
- Set memory limits explicitly. Always set container/JVM/Node heap limits. Never rely on defaults in production.
Heap Snapshot Analysis