我一直在尝试编写一个代码,我可以看到在设置超时和下次删除时不应该增加heapused。但无论heapUsed是不断增加的。
var process = require('process');
var initial = process.memoryUsage();
console.log("initial",initial.heapUsed);
var x;
function Happen() {
var prop = process.memoryUsage();
console.log("process",prop.heapUsed);
if(x)
clearTimeout(x);
x = setTimeout(function() {
Happen();
}, 500);
}
Happen();
答案 0 :(得分:0)
使用setImmediate在超时中回调Happen时清除上下文:
x = setTimeout(function() {
setImmediate(Happen);
}, 500);