From what I know about native JavaScript WeakMaps, they store their keys weakly, but store their values strongly, is that correct?
If so, would using a value as both, a key and a value in a WeakMap prevent the object from being garbage-collected?
const domElement0 = ...;
const domElement1 = ...;
const map = new WeakMap([
[ domElement0, domElement1 ],
[ domElement1, domElement0 ]
]);
Assuming that the WeakMap is always available, in that snippet, I would assume that, if domElement0
is unreachable, then domElement1
would not be garbage-collected, and vice versa, but if they both become unreachable and detached from the DOM, can I know that they will both become eligible for GC in most browsers?
If so, can someone provide a reference to why this is possible?