Feature-Request: allow to iterate over WeakSet / WeakMap

Boris Zbarsky bzbarsky at mit.edu
Wed Jul 13 15:38:24 UTC 2016

On 7/13/16 10:59 AM, Michael Kriegel wrote:
> So what does gc do to determine, whether an object still has hard
> references pointing towards it?

The GC may be conservative, not be precise.  That is, it may not collect 
some stuff that actually could be collected because the GC thinks there 
are references to it, while there actually aren't any.  The stuff may 
then end up being collected on a later collection, again depending on 
the contents of things like the machine stack and machine registers.

> Depends on how the gc works. If "deleting the last reference to an
> object" leads to an immediate deletion of all references to other
> objects held by this object, then: no.

I'm not aware of any JS GC that uses reference counting.  It _could_ be 
done, together with a cycle collector, but you'd really really need the 
cycle collector.  And once you have a cycle collector, you need to run 
it to find out whether things really are unreachable; just looking at 
reference counts is no longer enough.

> Any resources on what they do? E.g. chrome V8 or Firefox?

SpiderMonkey (the JS engine in Firefox) uses a tracing GC.  In terms of 
the "implementation strategies" described at 
https://en.wikipedia.org/wiki/Tracing_garbage_collection it's a moving, 
mark-and-sweep, generational, incremental, precise collector.


More information about the es-discuss mailing list