Thoughts on WeakMaps

David Bruant david.bruant at labri.fr
Mon Jun 6 14:31:59 PDT 2011


Hi,

I'm currently working on the WeakMap documentation [1] and I have
thought of two points:
1) myWeakMap.set(key, value) doesn't return anything. It could return
the previous value for the key (if such a thing exists). Is it
intentional that the set function doesn't return anything?

2) The notion of weak reference as used in current WeakMap seems to be
assuming that the garbage collector will work on whether objects are
reachable or not. I have read (I thought it was the wikipedia page, but
it apparently wasn't) that there is another notion for garbage
collection which is whether an object will be used or not in the future.
Of course, this notion is far more difficult to determine than
reachability, but this is not my point.
Let imagine for a minute that a lot of improvements is done in the field
of object non-future-use. Will WeakMap be any different than a regular Map?
If an engine is able to tell that an object will not be reachable, does
it matter if there are remaining (soft or strong) references?

The consequence of this second point is wondering whether it's a good
idea to standardize WeakMap (instead of Map) at all.

David

[1]
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/WeakMap
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110606/45252822/attachment.html>


More information about the es-discuss mailing list