liveBook · Manning

Memory profiling

As explained in Fast by Default

Memory profiling is the measurement and analysis of an application's memory allocation, retention, and reclamation behavior.

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

How Fast by Default covers it

How deep it goes
Explains a repeatable snapshot comparison workflow and platform tools, but stops short of detailed garbage-collector internals.
Examples
Uses article navigation, batch processing, growing caches, Node.js requests, Go pprof, and Java heap snapshots as diagnostic cases.
What it assumes
Assumes familiarity with application actions and retained objects while teaching the comparison workflow from its diagnostic starting point.
What you can do after
Diagnose memory growth with heap snapshots, tracemalloc, Chrome DevTools, pprof, VisualVM, or Eclipse Memory Analyzer.
How it connects
Connects memory leaks with garbage collection, heap snapshots, caches, event listeners, single-page applications, and backend services.

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.