Memory profiling measures allocation, retention, and reclamation behavior to reveal objects that remain alive after their work should be complete. It matters most in long-lived sessions and single-page applications, where small leaks accumulate across navigation until the application slows or crashes. section 7.1.3
Use a snapshot-compare-investigate workflow:
- Perform the self-contained action under suspicion, such as navigating away from an article and returning or processing a batch. section 7.1.3 section 7.2.4
- Capture a baseline snapshot, run garbage collection when available, repeat the action, and capture a second snapshot. section 7.1.3 section 7.2.4
- Compare snapshots, sort by size delta, and investigate object types or allocation sites with large net growth. section 7.1.3 section 7.2.4
- Check whether growing data serves one request or the whole application; bound long-lived caches and remove stale references, listeners, or collections. section 7.2.4
Detecting a navigation leak
A single-page news application takes a heap snapshot, navigates away from an article, returns, and captures another snapshot. If 200 HTMLDivElement objects appear without deletions, the view is creating elements that remain retained. Browser Memory panels expose this pattern; Node.js can use the same workflow through Chrome DevTools with --inspect. section 7.1.3 section 7.2.4
Figure 7.4 The snapshot-compare-investigate pattern for memory profiling and leak detection.

Follow the snapshot-compare-investigate diagram to connect reproduction, snapshots, comparison, and investigation. section 7.1.3
