I read that node.js is single-threaded, so it doesn't fork a new process or start a new thread for each http request. But then does the http module have a way of cleaning up after it closes each connection? For example, if I create an object inside the callback every time someone requests a page, does that object get destroyed once the response is served and the connection is closed?
Yes this true is due to scoping.
http.createServer(function(res) {
var localobject = new BigObject();
...
res.end();
});
Once you end the function the BigObject is no longer in use and gets cleaned up by the garbage collector.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With