Search code examples
javascriptgarbage-collectionjavascript-objectsv8

How does V8 handle objects in "large object space"


I've read in V8 wiki that there's large object space in heap which is not moved by GC.

Large-object-space: This space contains objects which are larger than the size limits of other spaces. Each object gets its own mmap'd region of memory. Large objects are never moved by the garbage collector.

Then how does V8 handle that objects? So if I have object like this

function Point() {
  this.a = new Array(99999999).join("aaaaaaaaaa");
  this.b = new Array(99999999).join("aaaaaaaaaa");
  this.c = new Array(99999999).join("aaaaaaaaaa");
}
var a = new Point();

it will be moved to large object space and never cleaned by GC?


Solution

  • (V8 developer here.) Bergi's comment is correct. Large objects are not moved to large object space, they are created in large object space. As long as they are alive, they are not moved. But they are garbage collected like any other object: when the GC detects that they are no longer live, the memory will be freed. In general, freeing dead objects does not involve moving them.