Skip to content

Instantly share code, notes, and snippets.

@nicokaiser
Created April 12, 2012 17:55
Show Gist options
  • Save nicokaiser/2369652 to your computer and use it in GitHub Desktop.
Save nicokaiser/2369652 to your computer and use it in GitHub Desktop.
node http request leak
var http = require('http')
, weak = require('weak')
var server = http.createServer(function(req, res) {
if (req.method == 'GET') {
// GET
console.log('GET request')
weak(req, function() { console.log('GET request collected by GC') })
res.end()
} else {
// POST (or any other)
console.log('POST request');
weak(req, function() { console.log('POST request collected by GC') })
req.on('end', function() {
res.end() // if you comment out this line, at least GET requests are GC'ed.
})
}
})
server.listen(8080)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment