Coding
AI Prompt for Diagnosing Memory Leaks
Find memory leaks fast with this AI prompt: spot leak patterns in your code, follow step-by-step detection with your profiler, and get a proper fix.
The prompt
Role: You are a performance engineer who diagnoses memory leaks in [LANGUAGE] applications. Context: My [LANGUAGE] app ([FRAMEWORK_OR_RUNTIME]) slowly consumes more memory over time until it crashes or slows down. Symptoms: [SYMPTOMS, e.g. heap grows 50MB/hour, GC pauses increasing]. Suspect area of code: [CODE_SNIPPET]. I have access to [PROFILING_TOOLS, e.g. Chrome DevTools heap snapshots, VisualVM, none yet]. Task: 1) Review my code and list specific leak patterns you can see (unclosed resources, growing caches without eviction, forgotten listeners/subscriptions, global accumulators, etc.). 2) Give me a step-by-step detection procedure using [PROFILING_TOOLS] to confirm which pattern is the real leak. 3) Provide the fixed code that properly releases resources. 4) Suggest a monitoring check I can add so this is caught automatically next time. Format: Numbered findings with severity (high/medium/low), then the detection steps, then fixed code, then the monitoring suggestion. Constraints: Focus on my suspect code first, but mention other common leak sources in [FRAMEWORK_OR_RUNTIME] briefly. Do not recommend increasing heap size as the fix.
Variables to fill in
Replace each [variable] in the prompt with your own details:
[LANGUAGE] [FRAMEWORK_OR_RUNTIME] [SYMPTOMS] [CODE_SNIPPET] [PROFILING_TOOLS]
Example input
LANGUAGE=JavaScript, runtime=Node.js Express server, symptom=RSS grows 100MB/day, suspect=event listeners added per request, tools=Chrome DevTools
How to use this prompt
Describe the growth pattern (how fast, when it started) — steady growth points to leaks, spikes point elsewhere. Name your profiling tools so the steps are concrete.
Tips for the best results
- Take two heap snapshots an hour apart and ask the AI to interpret the comparison if possible export them.
- Event listeners and caches are the top two leak sources — check those first.
- Ask for a load-test script that reproduces the leak quickly instead of waiting hours.
Frequently asked questions
How do I know it is a leak and not just high usage?
Memory that grows steadily under constant load and never drops after GC is a leak. The prompt's detection steps confirm this with snapshots.
Can AI find leaks without running my code?
It can spot classic leak patterns in code and design your detection procedure, but confirming the leak needs real profiling data — paste snapshot summaries back for analysis.