{Weak|}{Map|Set}

Andreas Rossberg rossberg at google.com
Fri Sep 16 05:14:57 PDT 2011


On 16 September 2011 13:52, David Bruant <david.bruant at labri.fr> wrote:
>
> Furthermore, let imagine for a minute that i need an ECMAScript
> implementation for programs i write which i know (for some reason) all are
> short live and use a maximum finite amount of memory i know. Based on this
> knowledge (i admit this to be weird to have this knowledge), i could decide
> to not implement a garbage collector. My programs are short-live and use few
> memory, i may not need to care about the memory.
>
> In this imagniary ECMAScript environment without Garbage Collection, why
> would i care of references to be weak or strong? I don't, i write programs.

Right, but why would you care about WeakMap either? The canonical Map
is perfectly fine for that situation.

> Also, the notion of garbage collection is a separate concern from
> programming. It comes from the necessity of being careful of resources.

Well yes, but that's part of programming. In practice, all resources
are finite. And the difference between finite and infinite space usage
is a correctness criterium.

Consider writing a server. If I cannot rely on tail call optimization
then writing its message loop as a recursive function (e.g. actors
style) would be incorrect. If I cannot rely on GC, then allocating an
object for each received message would be incorrect. If I cannot rely
on weak maps, then, say, mapping every message object to a return IP
would be incorrect.

/Andreas


More information about the es-discuss mailing list