liveBook · Manning

Heap

As explained in JavaScript in Depth

A region of memory used for dynamic allocation of objects and other data whose size or lifetime is not fixed at compile time.

A server-rendered request can allocate several megabytes of short-lived objects, fill V8’s young generation, and trigger garbage collection many times per second. The heap is the memory region where those objects live; collection reclaims unreachable objects so their memory can be reused. section 9.2.1 section 2.2.2

V8 organizes heap storage into progressively specialized regions:

  • Pages divide the heap into fixed-size blocks, typically around 256 KB, and may contain unrelated heap objects. section 2.2.2
  • The young generation uses two semi-spaces, with one active and the other reserved as the next copying target. section 9.2.1
  • Objects surviving two scavenges are promoted to the old generation, where collection is more expensive. section 9.2.1
  • Oversized allocations bypass the young generation and enter the Large Object Space, where each receives a dedicated page. section 2.2.2 section 9.2.1

A string changes storage region

V8 stores strings as heap objects. A string smaller than 128 KB stays on a regular page; a larger string goes to the Large Object Space. The ECMAScript limit is abstractly enormous, but the runtime imposes practical implementation limits. section 2.2.2

Figure 9.3 V8 divides its heap into distinct spaces. The young generation contains two semi-spaces (from-space and to-space), only one active at a time. Objects that survive two scavenges are promoted to the old generation. Allocations too large for the young generation go directly to the large object space.

Use the heap-layout figure to trace semi-spaces, promotion after scavenges, and direct large-object allocation. section 9.2.1

How JavaScript in Depth covers it

How deep it goes
Descends from heap definition to pages, generations, promotion, and large-object placement, while deferring detailed memory-management internals.
Examples
Uses strings, server-rendering object trees, closures, callbacks, pages, semi-spaces, and large-object allocation as concrete cases.
What you can do after
Evaluate how object size, reachability, survival, and allocation rate affect V8 heap placement and collection behavior.
How it connects
Connects heap storage with garbage collection, generational collection, call stack, young generation, old generation, and Large Object Space.

Also explained in

Compare how 11 books explain heap →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of JavaScript in Depth. The section links point to the parts of the book it draws on.