3 ms·
You and I had this exact conversation at Eataly a few months back. WeakMaps are cool, but JS is a garbage-collected language. All you have to do to GC something
by krebby 11y ago
You and I had this exact conversation at Eataly a few months back. WeakMaps are cool, but JS is a garbage-collected language. All you have to do to GC something is stop referencing it.
WeakMaps are only really useful when you don't control the referenced object's lifecycle. Even then, you can simply invert your map or check in your callback.
- daurnimator 11y ago> JS is a garbage-collected language. All you have to do to GC something is stop referencing it. That works well for JS... but if you are trying to use asm.js (or now wasm), you need to act on things getting garbage collected inside of your code.
- krebby 11y agoYou're talking about implementing your own GC inside JS. A valid use case, but a niche one. JS the language doesn't really need to expose GC internals. JS the compile target does. (Though it can be worked around).
- daurnimator 11y ago> You're talking about implementing your own GC inside JS. A valid use case, but a niche one. Any asm.js code that calls into DOM apis is going to need this. Otherwise they don't know when to free stuff. Most of the current asm.js code out there just binds a single canvas element, and works with that. But if you want to actually call anything else....