Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Finalizers aren’t destructors. The finalizer doesn’t get access to the object being GC’d, for one. But even more crucially, the spec allows the engine to call your finalizer anywhere between long after the object has been GC’d, and never.

They’re basically a nice convenience for noncritical resource cleanup. You can’t rely on them.



Yes? Congratulation you know what a finalizer is?

I was replying to this:

> would very explicitly cause the GC to have semantic effects, and I think that goes strongly against the JS philosophy.

Do you disagree that a finalizer provides for exactly that and thus can not be "strongly against the JS philosophy"?


I mean it’s an explicit violation of that philosophy as noted in the proposal:

> For this reason, the W3C TAG Design Principles recommend against creating APIs that expose garbage collection. It's best if WeakRef objects and FinalizationRegistry objects are used as a way to avoid excess memory usage, or as a backstop against certain bugs, rather than as a normal way to clean up external resources or observe what's allocated.




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

Search: