我有以下代码:
var constructors=[];
var counter = 0;
function start() {
for (var i=100; i> 0; i--) {
constructors.push(new arrayValues());
}
if (counter < 10) {
setTimeout(function() {
start();
}, 1000);
}
counter++;
}
function arrayValues() {
this.values = new Array(10000000).join("x");
}
这会创建虚拟数组并造成内存泄漏。这种模式在时间轴上清晰可见。但我也可以看到有对象的释放(用红线标记)。有没有办法找到有关正在释放的对象的任何信息,例如它们创建的时间或地点等?
问题不是如何通过分析代码找到信息,而是使用crhome-dev-tools找到信息
最佳答案
The question is not how to find the information by analyzing the code, but to find it using crhome-dev-tools
如果正确解释问题,您可以使用 console.profile()
, console.profileEnd()
; 记录堆分配
参见
profiling anonymous javascript functions (chrome)
Are arrow functions optimized like named functions?
How to detect the memory allocations that are triggering garbage collection in JavaScript?
关于javascript - 有没有办法找到有关使用 chrome 开发工具释放的对象的任何信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39728030/