Modern JavaScript also supports ephemerons.<p>There it's the WeakMap type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap" rel="nofollow">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...</a><p>WeakMap prevents observing when the weakly referenced key objects are garbage collected. It does this by being deliberately non-enumerable (see the MDN link). So it may be considered missing part of the definition of ephemerons. It has the weak-key part without the finalizer part.<p>But modern browsers support WeakRef and FinalizationRegistry, which eventually reveal when objects have been garbage collected. <a href="https://v8.dev/features/weak-references" rel="nofollow">https://v8.dev/features/weak-references</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry" rel="nofollow">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...</a> and <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef" rel="nofollow">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...</a><p>So this part of the WeakMap design is just an annoying obstacle which can be worked around.<p>(Note, as FinalizationRegistry is designed to accompany WeakRef, it's intriguing that MDN lists Opera as supporting FinalizationRegistry but not WeakRef.)
That's a complete but quite a long explanation, and talks in terms of Squeak which I'm unfamiliar with. I'm much more familiar with JavaScript WeakMaps, where I would probably describe it something like:<p>A WeakMap M is a table of entries, each of which maps a key K to a value V. If you have the M and K in hand, you can use them to look up V. (And if you don't have either one, then you can't!)<p>From a GC perspective, each entry is an edge that says that V is alive if both M and K are alive[1]. (And if either of them dies, then the entry no longer serves to keep anything alive. Note the parallelism with the above parenthetical.)<p>They're mostly useful for associating a value V with some other object K without modifying K. They're sort of an annotation mechanism. If you tried to do that with a regular Map, then you would have to manually remove any Ks that you wanted to go away.<p>In implementation terms, ...y'know, why don't I write it up as a blog post: <a href="https://blog.mozilla.org/sfink/2022/06/09/ephemeron-tables-aka-javascript-weakmaps/" rel="nofollow">https://blog.mozilla.org/sfink/2022/06/09/ephemeron-tables-a...</a><p>[1] Note that WeakMaps are not "weak" in the sense of weak references; the name WeakMap is a bit of a misnomer. Normal weak things can be skipped during marking. After liveness is determined, you'll check to see if they're still alive. You can't skip ephemeron edges like this! They're strong edges and it's invalid to throw away a V if its M and K are live. But EphemeronTable <i>is</i> a bit long...