Reputation: 3608
Node.js will do auto garbage collections ?
var objUser = new Object ();
objUser.userName = objReq.userName;
userDB.registerUser (objUser , callback) ;
In the above code I have "objUser" which will be passed as an argument to another class and it is no longer required in the present class. Still, should I have to forcefully collect it or will it do automatically.
To do it manually, Will NULL help or is there any other mechanism given by Node Framework?
objUser = null;
Upvotes: 1
Views: 1605
Reputation: 493
Also worth noting on this subject: It's been my experience that objects of the same type will reuse instances. So, if you truly want a "new Instance()" of an object make sure you nullify or reset any attributes in your constructors
Upvotes: 0
Reputation: 43158
Node does garbage collection, but if userDb.registerUser()
retains a reference to it, your objUser
will not be collected. Only when no references to an object remain it will be collected. You usually don't need to explicitly release local references by assigning null
to the variable — when your function returns, all local references are released automatically. You need to worry only about global references to your object.
Upvotes: 3