This is my sixth day of the August Challenge

Heap memory release problem: if the current heap is occupied [address is referenced, it cannot be freed, if not, the browser will free it when it is idle]

GC: The browser’s garbage collection mechanism

  • Reference count [add 1 when used, subtract 1 when unapplied, and release it when reduced to zero]
  • Reference detection/tag clearance [make a mark when it is occupied, when the reference is removed, the tag is unmarked, and all unmarked memory is reclaimed when the browser is idle]

Null [null object pointer, without opening any position]

It is important to learn to draw this kind of diagram to help us understand the analysis topic clearly, which is mainly related to closures and memory release

// EC(G)
// x=10
// fn = 0x000 [[scope]:EC(G)]

let x= 10;
function fn({
    / / EC (FN) closure
    // y = 20
    // f=0x001[[scope]:EC(FN)]
    let y = 20;
    function f({
        console.log(y)
    }
    window.f = f;
}
fn();
fn = null// The 0x000 heap is freed, but the previous context is not affected
f(); / / - > 20
window.f = null // The 0x001 heap is freed. At this point, EC(FN) has no external content and is freed
Copy the code