admin管理员组文章数量:1332107
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(){
var o = { foo: {} };
console.log(o);
}())
// Can o be collected?
If yes, are there any circumstances where writing to the console (using any of its methods) can affect eligibility for garbage collection?
Edit: I dont believe it will affect eligibility for collection based on watching the heap in Chrome dev tools. But will any category of writing to the console do so?
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(){
var o = { foo: {} };
console.log(o);
}())
// Can o be collected?
If yes, are there any circumstances where writing to the console (using any of its methods) can affect eligibility for garbage collection?
Edit: I dont believe it will affect eligibility for collection based on watching the heap in Chrome dev tools. But will any category of writing to the console do so?
Share edited Mar 3, 2015 at 19:07 Ben Aston asked Mar 3, 2015 at 18:50 Ben AstonBen Aston 55.8k69 gold badges220 silver badges349 bronze badges 2- 5 Chrome sometimes adds a note to logged objects, something like "evaluated upon first expansion". This suggests that the object might have been GCd in the meantime. But it could also just refer to modifications. – Thomas Commented Mar 3, 2015 at 18:52
- @Thomas I'm pretty sure it's referring to modifications. – Scimonster Commented Mar 3, 2015 at 18:56
1 Answer
Reset to default 6If 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“.
本文标签: javascriptWill consolelog prevent garbage collectionStack Overflow
版权声明:本文标题:javascript - Will console.log prevent garbage collection? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742265248a2443266.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论