
- Updated
Track down a memory leak
Memory that keeps growing until the app restarts usually comes from caches, listeners or timers that never let go. This prompt reviews your suspicious code and gives a step-by-step plan to confirm the leak with a profiler.
Act as an expert in [RUNTIME, e.g. Node.js / Python / Java] memory issues. Symptom: [e.g. memory grows from 200 MB to 2 GB over 6 hours, then the app restarts] What the app does: [SHORT DESCRIPTION] Suspicious code: [PASTE: caches, event listeners, timers, global lists] List the most likely leak sources in this code, explain why each one keeps memory alive, and show the fix. Then give me a step-by-step plan to confirm the leak with a heap snapshot or profiler, including exactly what to compare between two snapshots.
Common leaks: listeners that are never removed, caches with no size limit, and timers that keep running after a request ends.
Get a better result
A ranked list of the likely leak sources in your code, why each keeps memory alive and how to fix it, plus steps to confirm with a heap snapshot or profiler and what to compare between snapshots.
The suggestions are generic, such as “close your connections”.
Fix: Paste the real suspicious code and give the growth pattern with numbers. Ask for the specific line and the reason.
- You change code before proving there is a leak. Take one snapshot early and one after the memory has grown, as the plan says, and compare which objects increased.
- A cache grows forever. Ask for “a size limit and an expiry time on each cache, with the reasons for the numbers”.
Ask for “a small check that logs memory use every minute and warns above a limit”. It tells you early if the fix worked and when the leak returns.
Assume the leak is in the event listeners. Show how to check that, then how to remove them when the object is done.
Guides that use this prompt
More chat & writing prompts
See all 465 →More like this
- Debug an error message step by stepChatGPT · Gemini · Claude
- Memory wall collageGemini · ChatGPT
- Clean a messy spreadsheet with PythonClaude · ChatGPT · Gemini
- Add logging that helps you debug laterClaude · ChatGPT · Gemini
- Cinematic memory pan across a photoKling · Veo · Seedance



