Node.js请求内存泄漏

鉴于以下代码片段:

var request = require('request'); function getGoogle() { request('http://www.google.com', function (error, response, body) { if (!error && response.statusCode == 200) { //console.log(body) // Print the google web page. } }); } setInterval(getGoogle, 1000); 

使用节点版本0.10.17,此代码泄漏。 任何想法为什么?

我看到很多问题,人们走“我的内存泄漏!” 基于应用程序运行的前几分钟,而不必等待进程达到上限或实际用完内存。 节点只是使用尽可能多的内存。

看下面的粗略的基准。 我运行了你的代码(而不是100的超时),内存使用量迅速增加到〜70 MB,但是停止了。 第一列是内存使用情况。

 27368 0:00.36 node test.js 40644 0:00.82 node test.js 47468 0:01.21 node test.js 48192 0:01.40 node test.js 67952 0:02.39 node test.js 69448 0:03.29 node test.js # Increasing fast til around here 70016 0:04.46 node test.js 70624 0:07.43 node test.js 70944 0:10.59 node test.js 71612 0:13.63 node test.js 73120 0:16.83 node test.js 70864 0:18.17 node test.js # Look it's decreasing 67780 0:42.27 node test.js # Considerably later it's even lower! 

我猜为什么这样会是因为垃圾收集是昂贵的,但我不确定,如果有人有一个真正的解释和参考,会很高兴。

在这个页面( http://www.joyent.com/blog/walmart-node-js-memory-leak ),他们实际上在Node.JS的http堆栈中发现了内存泄漏

好消息是它在Node.JS版本v0.10.22中被修复