Created
April 25, 2012 10:41
-
-
Save vvo/2488897 to your computer and use it in GitHub Desktop.
mem leak ?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('webkit-devtools-agent') | |
var | |
http = require('http'), | |
done = 0, todo = 30, doing = todo; | |
console.log('We should do '+ todo +' requests'); | |
http.createServer(function (req, res) { | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
res.end('Hello World\n'); | |
}).listen(3000, '127.0.0.1', getall); | |
// show memused and progress while running | |
setInterval(status, 5000);status(); | |
function getall() { | |
// creates a big buffer | |
var megabig = new Big(); | |
// this should not trigger a memory leak but it does when using http.get | |
function cb() { | |
done+=1; | |
return megabig; | |
} | |
while(doing--) { | |
http.get({ | |
hostname: 'localhost', | |
pathname: '/index.html?' + Math.random(), | |
port: 3000, | |
protocol: 'http:' | |
}, cb); | |
} | |
} | |
function Big() { | |
this.yo = (new Buffer(1 * 1024 * 1024 * 100)).toString(); | |
} | |
function status() { | |
var | |
mem = process.memoryUsage(), | |
rss = (mem.rss/1024/1024).toFixed(), | |
heapUsed = (mem.heapUsed/1024/1024).toFixed(), | |
heapTotal = (mem.heapTotal/1024/1024).toFixed(); | |
console.log('rss: %dMB, heapUsed: %dMB, heapTotal: %dMB',rss, heapUsed, heapTotal); | |
console.log('Done: '+ done +'/'+ todo); | |
if (done === todo) { | |
console.log('All requests done, memory should be collected') | |
} | |
} |
thx :)
http.request + req.end() needs less memory ! see : https://gist.github.com/2503608
(but memory leak is still there ...)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
url & request modules seem to be unused, you should remove them