3 ms·
A drawback of standard weak references is that it exposes garbage collector scheduling to the program, which would make JS programs more nondeterministic. I bel
by mccr8 14y ago
A drawback of standard weak references is that it exposes garbage collector scheduling to the program, which would make JS programs more nondeterministic. I believe that historically nondeterminism like this has been a source of incompatibility between JS implementations.
- wycats 14y agoThe current proposals avoid this problem by requiring that objects held by weak references can only be observably collected between turns of the event loop. In short: whenever a WeakReference is dereferenced, a temporary strong reference to the object is created that is dropped at the end of the turn of the event loop. There might still be non-determinism, but it is limited to the type that is already common in JS. Behavior across event turns (i.e. happening in asynchronous callbacks) cannot make any assumptions about what else may have happened between callback registration and callback execution.