3 ms·
> ran into the restrictions on collection visibility Is there any more information about this? It seems really subtle!
by brrrrrm 5y ago
> ran into the restrictions on collection visibility
Is there any more information about this? It seems really subtle!
- pwdisswordfish9 5y agoBasically, looking at the target of a WeakRef makes it ineligible for collection until at least the next await, which the spec mandates by way of the [[KeptAlive]] list. This is meant to prevent TOCTOU bugs by foolish programmers doing this: if (weakref.deref()) { /* garbage collection here */ use(weakref.deref()); }
- josefx 5y agoIsn't that a rather narrow case? What happens on the following, is that protected? if (weakref.deref()) { /* garbage collection here */ use(heavyComputations(), weakref.deref()); }
- pwdisswordfish9 5y agoYes, as long as there is no intervening suspension (await, or the script otherwise exiting to the event loop).