JavaScript WeakMaps are not actually weak: they refer strongly to their contents as long as the key is alive.
This brings the list of imprecisely-named ECMAScript APIs to:
Map → OrderedMap
Set → OrderedSet
Promise.race → Promise.anySettled
WeakMap → Ephemeron
-
-
Weak references can be constructed with weak maps. I am fairly sure weak maps *are* the lower level implementation, since this pattern also exists in java.pic.twitter.com/HeYCe5Y1qd
-
That example leaks, though. The point of WeakRefs is that you can keep `weakreference` around forever without preventing its target from being garbage-collected.
- 1 more reply
New conversation -
-
-
WeakRefs are often too powerful though. WeakMaps really should continue to be used for use cases where they are sufficient
-
Definitely. I’m not hating on WeakMaps — just on their name

- 6 more replies
New conversation -
-
-
The reason why the proposal for weakPointers was not implemented is, that in javascript you shell not be allowed to detect when the garbage collector has run. This was argumented as security measurement. Just FYI
-
In node there is a hack for weak pointers as native plugin btw.
End of conversation
New conversation -
-
-
WeakMaps have one use case: keeping library-specific metadata on mutable objects it does not control (usually a DOM node). I remember needing that all the time in the jQuery era of webdev (when I could rarely use it!); not so much in the React era.
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
I've just always known weak to be about garbage collection. Is this the only language that uses weak this way? Even if it was, I'm not sure the name is all that bad. Your replacement for race is spot on though.
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
JavaScript, HTML, CSS, HTTP, performance, security, Bash, Unicode, i18n, macOS.
. What would you have to hypothetically change in WeakMap for it to be weak, and would it be useful functionality?