Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardJavaScriptclosures and memory retentionSingle-choice MCQ

In V8, every closure created inside the same function activation shares a single heap-allocated 'context' object that holds the captured variables. Given the code below, why does `getBig()` keep the large `payload` array alive even though it never references it?

function makeHandlers() { const payload = new Array(1e6).fill(0); // large const small = 42; function useBig() { return payload.length; } function getSmall() { return small; } return { getSmall }; // useBig is dropped, only getSmall escapes } const h = makeHandlers();