Javascript and Garbage collection

后端 未结 6 648
不思量自难忘°
不思量自难忘° 2020-11-28 04:19

Is there any way to control when Javascript performs garbage collection? I would like to enable it to perform garbage collection at certain times to ensure the smooth operat

6条回答
  •  半阙折子戏
    2020-11-28 04:36

    Why not keep references to all your objects until you want them to be GC'd?

    var delayed_gc_objects = [];
    function delayGC(obj) { // keeps reference alive
        return delayed_gc_objects[delayed_gc_objects.length] = obj;
    }
    function resumeGC() { // kills references, letting them be GCd
        delayed_gc_objects.length = 0;
    }
    

提交回复
热议问题