Search code examples
node.jsv8

What are v8 old space and new space?


Node.js has two parameters to control memory allocations as I know of:

--max_new_space_size and --max_old_space_size

What exactly are 'new space' and 'old space'?


Solution

  • In a generational garbage collector (which V8 uses), the heap is generally divided into two spaces. A young generation (new-space) and an old generation (old-space). Infant mortality or the generational hypothesis is the observation that, in most cases, young objects are much more likely to die than old objects.

    New-space: Most objects are allocated here. New-space is small and is designed to be garbage collected very quickly, independent of other spaces.

    Old-space: Contains most objects which may have pointers to other objects. Most objects are moved here after surviving in new-space for a while.

    Ref: http://www.memorymanagement.org/glossary/g.html#term-generational-hypothesis

    Ref: http://jayconrod.com/posts/55/a-tour-of-v8-garbage-collection