Example result: Track down a memory leak
AI-generated example · Debug · Memory Leak
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.

text-code-memory-leak-hunt — claude — 90 words

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

What you will get

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.

Common mistake

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.

Also watch for
  • 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”.
Try a variation: add a memory alarm

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.

Still not right? Reply with this

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 →