What is the status of Weak References?
bruant.d at gmail.com
Fri Feb 1 02:06:37 PST 2013
Le 31/01/2013 22:48, Kevin Gadd a écrit :
> I ask this because the lack of weak references (or any suitable
> substitute mechanism) comes up regularly when dealing with the
> consider extremely elaborate workarounds just to build working
> applications (like storing*all* their data in a virtual heap backed
> by typed arrays and running their own garbage collector against it).
> If there is really a firm reason why this must be so, so be it, but
> seeing so many people do an end-run around the JS garbage collector
> something is wrong. The presence of WeakMaps makes it clear to me that
> solving this general class of problems is on the table.
I don't understand the connection between the lack of weak references
and emulating a heap in a typed array.
> Historically the lack of weak references has resulted in various
> solutions in libraries like jQuery specifically designed to avoid
> cycles being created between event listeners and DOM objects. Many of
> these solutions are error-prone and require manual breaking of cycles.
Garbage collectors have evolved and cycles aren't an issue any longer,
weak references or not.
> But on the
> other hand I've been told in response to this question before that
> TC39 has a general policy against features that allow garbage
> collection to be visible to applications.
I'm not part of TC39, but I'm largely opposed to anything that makes GC
observable. It introduces a source of non-determinism; that is the kind
of things that brings bugs that you observe in production, but
unfortunately didn't notice and can't reproduce in development
environment. Or if you observe them when running the program, you don't
observe it in debugging mode.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss