何为垃圾?

test在栈内存,{ name: “test”}和[1, 2, 3, 4, 5]都在堆内存中,{ name: “test”}被覆盖掉了,成了堆内存中的垃圾。

1
2
3
4
5
let test = { name: "test"};

test = [1, 2, 3, 4, 5];

console.log(test);

引用计数法

是一种早期浏览器使用的方法。