a-tonchev / rest-api-boilerplate

Boilerplate for Rest API with authentication, based on KOA and mongodb driver with JSON Schema validation (which is native for mongo)
4 stars 0 forks source link

Why have you dereferenced ctx explicitely? #19

Open Dhruv-Garg79 opened 1 year ago

Dhruv-Garg79 commented 1 year ago

Hey first of all thanks for this project, I was exploring uWebSockets.js.

I was going through your code and saw that you have explicitly dereferenced ctx = null in setupRouteHandlers.js file.

According to my understanding, it will get dereferenced on it's own when the function block ends. please correct me If I am wrong.

a-tonchev commented 1 year ago

@Dhruv-Garg79 that is correct. But this way I just make the work of the garbage collector a little bit easier 🙂 An this way also other programmers can see - this is the end.

Dhruv-Garg79 commented 1 year ago

But how does that make the work of GC easier? you have just derefernced it, GC will work the same if you derefernced it yourself, or node.js does it. GC reclaims the memory for objects that are not reachable(dereferenced), it does not dereference them itself, right?

The other point regarding - this is the end. seems nice.

a-tonchev commented 1 year ago

@Dhruv-Garg79 my logic is - GC need a little bit more time to understand when the object is not reachable. This way you tell it directly.

Don't think about this too much, it probably have no difference

Dhruv-Garg79 commented 1 year ago

yeah, got it. Just wanted to understand If I am missing something.