1

Since GC detects isolated islands of object graph to find candidates for removal from memory and WeakMap does not break island boundaries with it's weak references WeakMap -> KeyObject then it would make sense for this reference WeakMap -> Value -> KeyObject to also not break island boundaries with weak WeakMap -> Value reference, while Value -> KeyObject reference is obviously strong.

Example:

let o = {test:1};
let map = new WeakMap();
map.set(o, {strongRef: o});
o = null; // clear last reference on {test:1}
// will {test:1} be GCed after this ?
alpav
  • 2,972
  • 3
  • 37
  • 47
  • Please leave a comment if you think it's not a dupe and I'll reopen it. – zerkms Oct 13 '16 at 01:07
  • 2
    Potential duplicate: http://stackoverflow.com/q/32687100/251311 – zerkms Oct 13 '16 at 01:36
  • 1
    The key to understanding mentioned duplicate question is to realize that "circular" means half of circular. Full circular would be references map->Value->KeyObject->map, but "circular" is only map->Value->KeyObject. – alpav Oct 13 '16 at 02:05
  • Possible duplicate of [Would a "circular" reference be treated as "reachability" for a WeakMap?](https://stackoverflow.com/questions/32687100/would-a-circular-reference-be-treated-as-reachability-for-a-weakmap) – ZunTzu May 02 '18 at 09:46

0 Answers0