Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does node.js clean itself up after requests?

Tags:

node.js

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?

like image 604
Kevin McTigue Avatar asked Jul 28 '11 21:07

Kevin McTigue


1 Answers

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.

like image 184
Raynos Avatar answered Oct 12 '22 02:10

Raynos