JavaScript memory management
March 03, 2019 JavaScript
- All variables are part of the the object graph
- Object variables can reference other variables
-
Objects has two sizes :
- shallow: just the object
- retained: sum of shallow size of all descendents
- Garbage: all variables which cannot be reached from the root node
-
Garbage collection:
- find all garbage
- 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:
javascriptmemory management