liveBook · Manning

Heap snapshot

As explained in Fast by Default

A heap snapshot is a captured representation of the objects and memory allocations currently held in a program's managed heap.

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

How Fast by Default covers it

How deep it goes
Explains a repeatable comparison workflow and retention patterns, but defers runtime-specific heap internals.
Examples
Uses article navigation, repeated requests, Node.js inspection, Go pprof, and Java memory analyzers.
What it assumes
Assumes familiarity with application navigation or requests and introduces garbage-collection-assisted snapshot comparison from the workflow.
What you can do after
Diagnose memory growth by capturing, comparing, sorting, and investigating snapshots across supported profiling tools.
How it connects
Connects garbage collection, memory leaks, event listeners, closures, caches, timers, and memory profiling.

Also explained in

Compare how 2 books explain heap snapshot →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Fast by Default. The section links point to the parts of the book it draws on.