Will console.log prevent garbage collection?

前端 未结 1 981
后悔当初
后悔当初 2020-12-15 19:39

If I have an object that would normally be garbage collected, but has been logged to the console, will it still be eligible for garbage collection?

(function         


        
相关标签:
1条回答
  • 2020-12-15 19:40

    If you log an object to the console it can not be garbage collected.

    You can verify this by entering in the chrome console:

    var Foo = function() {};
    console.log(new Foo());
    

    Go to “Profiles” and “Take Heap Snapshot”. This will do a garbage collection automatically. Search for class “Foo”. There will be a 1 in column “Objects count“.

    0 讨论(0)
提交回复
热议问题