垃圾回收机制的原理

(1)找出不再使用的变量
(2)释放其占用内存
(3)固定的时间间隔运行

  1. function test(){
  2. var a = 1;
  3. return function() {
  4. a++;
  5. console.log(a);
  6. }
  7. }
  8. var test = test1();
  9. test(); // 2
  10. test(); // 3
  11. test(); // 4
  12. test = null;
  13. test(); // 报错