假設我有一個簡單的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
這實際上有助於更常見的意義。謝謝:-) –