JavaScript memory management

March 03, 2019 javascript JavaScript
  • All variables are part of the the object graph
  • Object variables can reference other variables
  • Objects has two sizes :

    1. shallow: just the object
    2. retained: sum of shallow size of all descendents
  • Garbage: all variables which cannot be reached from the root node
  • Garbage collection:

    1. find all garbage
    2. return memory used by garbage variables to system
  • Allocating memory:

      -Every call to new

      • reserves memory for object from ‘young’ memory pool
      • cheap until...
      -Young memory pool runs out of memory

      • runtime forced to perform a garbage collections
      • can take milliseconds (!)
      -Interactive applications must be careful with object allocation patterns

      • games must strive for 0 allocation with a frame

Notes taken from: