3 ms·
For garbage collected languages destructors cannot be called synchronously in most cases because the VM must make sure that the object is inaccessible first. So
by senfiaj 1y ago
For garbage collected languages destructors cannot be called synchronously in most cases because the VM must make sure that the object is inaccessible first. So it will not work very deterministically, and also will expose the JS VM internals. For that JS already has WeakRef and FinalizationRegistry.
https://waspdev.com/articles/2025-04-09/features-that-every-js-developer-must-know-in-2025-part-2#weakref https://waspdev.com/articles/2025-04-09/features-that-every-...
https://waspdev.com/articles/2025-04-09/features-that-every-js-developer-must-know-in-2025-part-2#finalizationregistry https://waspdev.com/articles/2025-04-09/features-that-every-...
But even Mozilla doesn't recommend to use them because they're quite unpredictable and might work differently in different engines.