假设我有一个简单的HTTP服务器,如:在Node.js中使用流时会发生内存泄漏?
var http = require('http');
http.createServer(function (req, res) {
req.on('data', function (data) {
console.log('Got some data: ' + data);
});
req.on('end', function() {
console.log('Request ended!');
});
res.end('Hello world!');
}).listen(3000);
所以,基本上是默认101样品,没有什么特别的,到目前为止 - 除了我订阅data
和可读req
流的end
事件。现在我想知道当我不再需要这些事件时是否必须取消订阅这些事件?
或者当可读流结束时它们被自动清除吗?
像这样的代码会导致内存泄漏?
[This](http://stackoverflow.com/questions/5326300/garbage-collection-with-node-js)可能会有所帮助。 – hexacyanide
这实际上有助于更常见的意义。谢谢:-) –