How is junk data generated

Window.test =new Object() window.test.a=new Unit16Array()Copy the code

Principles of Garbage Collection

Keywords: Clear, tidy memory

Intergenerational hypothesis:

  1. Most objects have a short lifetime and live in memory for short periods of time, such as internal function declarations, block-level scopes, and the object is destroyed when the code or function is finished executing.
  2. Undead objects live longer. Certain objects live in memory for a long time, such as Window objects, DOM objects, Webapis, etc

Two areas: Young Space and Old Space

young space

Storage of temporary small objects corresponds to the first rule of the generation hypothesis

  • Sub-garbage collector algorithm:

In two areas: object area, leisure area, object area to store variable, after the object area is full, triggers garbage collection algorithm, garbage and eliminate tag object area, will still alive is copied to the leisure area (also drop in at this time to complete the memory), object area, exchange object area and leisure area, two is not clear, to upgrade to the old space

old space

  • Main garbage collector algorithm:

Mark-clear

Tags: Starting from the root node, tags that cannot be traversed clear: Clears inactive objects

Memory fragmentation is easy to occur. How?

Mark-tidy

Move all live objects to one side, then clear the remaining space