bi-04 step 03 — Lifetime, retention, and the retainer chain

Goal

Build a leak deliberately, then find it the way you would in production — by reading a retainer chain, not by guessing.

Tasks

  1. Forced synchronous layout. Write the read-then-write loop; measure at n = 100/1000/5000 and plot. Batch reads and writes; re-measure. Name the complexity class of each.
  2. Detached subtree leak. Remove a subtree while a JS variable retains it, with listeners closing over more state. Grow it until it is visible in a heap snapshot.
  3. Read the retainer chain, not the size. Which object is the root? In a two-heap system the chain may cross from a JS closure to a C++ node — this is the skill that transfers.
  4. Source reading. Find Element's Trace() method in Blink. List what it keeps alive. Predict what happens to a listener closure when the element is removed but a JS reference is retained, then verify.
  5. ActiveScriptWrappable. Explain why an XMLHttpRequest with no references survives until it fires, and what stops that becoming a leak.

Done when

  • Forced-layout measurements plotted, before and after batching
  • A leak built and located via its retainer chain
  • Trace() read; the ownership list written down
  • You can name three distinct leak shapes and their detection method