A heap snapshot is a captured representation of objects and memory allocations held in a program’s managed heap. Comparing snapshots reveals allocations that grow after an operation and identifies objects that remain reachable when they should have been released. section 7.1.3 section 7.2.4
The snapshot-compare pattern is especially useful in single-page applications, where navigation does not reload the page. Repeating navigation can accumulate leaked objects, slow the tab, or eventually crash it. section 7.1.3
Use a snapshot comparison to investigate suspected retention:
- Navigate to the target view or start the suspect operation. section 7.1.3
- Trigger garbage collection where the profiling tool supports it, then capture the first snapshot. section 7.1.3
- Navigate away and return, or repeat the operation and its traffic, then capture a second snapshot. section 7.1.3 section 7.2.4
- Compare snapshots, sort by size delta, and inspect objects with additions but no corresponding deletions. section 7.1.3
Common retention patterns include unreleased event listeners, closures holding DOM nodes or large data structures, unbounded caches, and timers that continue after components unmount. A clean comparison is useful as a regression baseline but does not guarantee future changes will remain leak-free. section 7.1.3
Cross-platform memory investigation
Browser DevTools can compare heap snapshots for a single-page article template. Node.js exposes the same mechanism through Chrome DevTools when started with --inspect. Go uses pprof heap profiles and diff mode, while Java supports comparable snapshots through VisualVM, Eclipse Memory Analyzer, jmap, or JMX. section 7.1.3 section 7.2.4
Figure 7.4 The snapshot-compare-investigate pattern for memory profiling and leak detection.

The snapshot-compare-investigate pattern provides a compact visual workflow for isolating memory growth. section 7.1.3

