Module 6 · Scope, Hoisting and Closures
Under the Hood: Environment Records, V8 Contexts and a Closure Memory Lab
ProReading
Maria's team dashboard runs in a browser tab all day. By the afternoon the tab uses hundreds of megabytes more than it did at nine. A heap snapshot points at a small function that only returns a label. It never reads the big array that the snapshot says it keeps alive. Maria asks her usual question: "But why would a function keep something it never uses?" This lesson answers it three times: in the language's specification, in the engine's bytecode, and with a measured lab.
Checking what this lesson needs for you…
What is inside Under the Hood: Environment Records, V8 Contexts and a Closure Memory Lab
- The specification's model: Environment Records
- The two passes, in the specification's words
- V8's version: one context per call, and registers
- The closure memory lab