Dev.Lib
arrow_backBack to Blogs
LEVEL_099.7June 27, 20261 min read

Browser memory leak detection

Performance Metrics

Heap snapshot diff — detached DOM, growing listeners, closures holding large graphs.

Summary

Heap snapshot diff — detached DOM, growing listeners, closures holding large graphs. Performance monitor JS heap trend over SPA navigations. Common: charts, maps, global caches without eviction. Fix teardown in useEffect return and route leave.

Code example

const baseline = performance.memory?.usedJSHeapSize;

function checkLeak() {
  const current = performance.memory?.usedJSHeapSize;
  if (baseline && current - baseline > 5_000_000) {
    console.warn('Heap grew by', current - baseline, 'bytes');
  }
}

Key points

  • Heap snapshot diff — detached DOM, growing listeners, closures holding large graphs.
  • Performance monitor JS heap trend over SPA navigations.
  • Common: charts, maps, global caches without eviction.
  • Fix teardown in useEffect return and route leave.

Further reading

Related concepts