【问题标题】:Why nodejs memory is not consumed for specific loop count为什么特定循环计数不消耗nodejs内存
【发布时间】:2017-02-10 08:05:01
【问题描述】:

我试图在我的代码中找到内存泄漏。我发现当 n 为 1

function somefunction()
{

    var n = 256;
    var x  ={};
    for(var i=0; i<n; i++){
        x['some'+i] = {"abc" : ("abc@yxy.com"+i)};
    }


}

// Memory Leak
var init = process.memoryUsage();
somefunction();
var end = process.memoryUsage();
console.log("memory consumed 2nd Call : "+((end.rss-init.rss)/1024)+" KB");

【问题讨论】:

  • 您输入的 n 值无关紧要。由于 x 是局部变量,它占用的内存将在下一次 gc 运行时释放。可能在您在 end 变量中记录 memoryUsage 时 gc 循环没有执行

标签: node.js memory-leaks


【解决方案1】:

它可能没有泄漏。您不能总是期望 gc 这么快就清除所有内容。

Why does nodejs have incremental memory usage?

如果要强制垃圾回收,请参阅

How to request the Garbage Collector in node.js to run?

【讨论】:

  • 感谢@cshu,但由于堆栈溢出中的 1
猜你喜欢
  • 2011-12-15
  • 2021-08-09
  • 1970-01-01
  • 1970-01-01
  • 2019-09-30
  • 2018-10-10
  • 1970-01-01
  • 1970-01-01
  • 2011-05-10
相关资源
最近更新 更多