Question about JS garbage collection

Will object literal #1 be garbage-collected once object literal #2 is assigned to m?

function garbage() {
    let m = {"object literal #1": true};
    let i = 0;
    while(i < 2) {
        if(!i) m["new prop"] = "new value"
        else m = {"object literal #2": true};
        i++;
    }
}

Yes. It will recognize that nothing is pointing to that object.

1 Like

The wonderful thing about automatic garbage collection is that you don’t need to think about the exact moment where it occurs.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.