CodeZettaInterview Hub

JavaScript · Memory Management · Senior · Debugging

How do you diagnose a memory leak using browser DevTools?

Short Interview Answer

Take heap snapshots over time, compare retained sizes, find retainer paths, and use allocation timelines while reproducing the leak scenario.

Detailed Explanation

Steps: force GC if available, snapshot baseline, reproduce navigation/actions N times, snapshot again, look for growing object counts (Detached HTMLDivElement, listeners, arrays). Inspect retainer path to see what keeps them alive (closure, module cache). Allocation instrumentation sampling helps find churn. In React, check for abandoned fibers/stores. Confirm fix with another comparison. Also monitor performance memory charts for upward trends that don't return to baseline after GC.

Interview Tip

Describe a before/after snapshot workflow — practical seniority.

Common Mistake

Judging leaks from a single snapshot without comparison or without forcing teardown.

Did you know this answer?