Hacker News new | past | comments | ask | show | jobs | submit login

I always found languages which require you to always remember to manually call destructors to be quite hard, be they C or Go or JavaScript, when the system has lots of moving parts and performance is a concern. A single mistake and you're leaking.



> remember to manually call destructors to be quite hard, be they C or Go or JavaScript

I thought JacaScript doesn’t have destructors (in the memory/resource management sense) or finalizers…


File handle destructor: https://nodejs.org/api/fs.html#filehandleclose

WebSocket's destructor: https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/c...

HTTP server's destructor: https://nodejs.org/api/http.html#serverclosecallback

Etc etc etc.

You're right that JS/C/Go don't have language features called destructors, but they have a whole bunch of types with ad-hoc destructor functions which you have to remember to call if you want to avoid leaking resources.


There's a proposal for syntax to help with this in JS, incidentally: https://github.com/tc39/proposal-explicit-resource-managemen...


Go doesn’t require you to call a destructor


Close, e.g., is a destructor in this context.

Defer helps but some true lexical scoping might be nicer.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: