What is the status of Weak References?

Kevin Gadd kevin.gadd at gmail.com
Thu Jan 31 13:48:55 PST 2013

A search shows some old discussions of the topic mentioning that they
might be going in to future versions of the language, etc. 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.

There's still a strawman up on the wiki:
http://wiki.ecmascript.org/doku.php?id=strawman:weak_references and
while it appears to be a relatively simple, sane way to expose weak
references, it looks like the strawman hasn't been touched since late
2011. Is that because it's dead? Or was it deprioritized because weak
references are believed to not be needed by JS application developers?

I ask this because the lack of weak references (or any suitable
substitute mechanism) comes up regularly when dealing with the
challenge of porting native apps to JavaScript, and it leads people to
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
only to implement their own *in JavaScript* makes me wonder if perhaps
something is wrong. The presence of WeakMaps makes it clear to me that
solving this general class of problems is on the table.

People are certainly solving this problem in other JS related contexts:
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.

To make a controversial statement, I would suggest that there are some
problems that cannot be solved in JavaScript unless it has an
approximation of weak references. I would love to be proven wrong here
because then I can use whatever your crazy computer science
alternative is. :D


More information about the es-discuss mailing list