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
- 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.
- 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.
- 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.
- Source reading. Find
Element'sTrace()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. ActiveScriptWrappable. Explain why anXMLHttpRequestwith 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