小编fac*_*ous的帖子

node.js文件内存泄漏?

我看到内存泄漏,使用以下代码:

while (true) {
  console.log("Testing.");
}
Run Code Online (Sandbox Code Playgroud)

我已经尝试定义字符串并只使用常量,但它会泄漏内存,仍然:

var test = "Testing.";
while (true) {
  console.log(test);
}
Run Code Online (Sandbox Code Playgroud)

如果我使用文件而不是标准日志,则会发生同样的泄漏:

var test = "Testing.";
var fh = fs.createWriteStream("test.out", {flags: "a"});
while (true) {
  fh.write(test);
}
Run Code Online (Sandbox Code Playgroud)

我想也许是因为我没有正确关闭文件,但我尝试了这个并且仍然看到了泄漏:

var test = "Testing";
while (true) {
  var fh = fs.createWriteStream("test.out", {flags: "a"});
  fh.end(test);
  fh.destroy();
  fh = null;
}
Run Code Online (Sandbox Code Playgroud)

有没有人有任何关于如何在没有泄漏记忆的情况下写东西的提示?

logging memory-leaks file node.js

8
推荐指数
1
解决办法
2118
查看次数

标签 统计

file ×1

logging ×1

memory-leaks ×1

node.js ×1