The difference is that if the large cycle is only uncollected because the
weak references haven't been zapped, in a low memory/out of memory
situation, the runtime's collector can go through and zap all weak
references. If I write an ES application and do my own cycle
collection/weak reference zapping, I have no way to respond to that low/out
of memory situation by doing a collection on demand, so instead my
application will run out of memory at arbitrary points in time.

The latency is not actually a major concern here, and I wouldn't argue that
weak references improve on latency. Weak references make it *possible* for
the language's collector to collect those cycles *at all*. Without them,
the only way they can be collected is if the *application* collects them,
and it has no trivial way to do so at the correct time.

I can't comment on how weak references would work in an ES collector
either, but I can imagine weak reference implementations that would not
prevent collection in the first place, so zapping would not be necessary in
order for those cycles to be collected. IIRC, some weak reference
implementations work by having the strong object maintain a list of the
weak references that point to it, and the weak references do not actually
keep the strong object alive. In such a scenario, you would not need to zap
references for the object to be collected; rather, collecting the object
would replace all the weak references with null, thus ensuring that the
dead object stays unreachable.

On Fri, Nov 8, 2013 at 2:42 PM, Allen Wirfs-Brock <[email protected]>wrote:

>
> On Nov 7, 2013, at 3:16 PM, Mark Miller wrote:
>
> I agree. This is a good use for weakrefs without the need for
> finalization. Thanks!
>
>
> On Thu, Nov 7, 2013 at 3:12 PM, K. Gadd <[email protected]> wrote:
>
>> The problem is that the cycles remain uncollectable for a very long
>> period of time, even though functionally the references don't need to be
>> strong.
>>
>
> Ah, these are all basically the same problem and you will likely see the
> same latency effects for all of them.  Any GC design where you may have
> serious latency for collection cyclic structures (for example, a
> generational heap where the circular structure crosses generations) is very
> likely to also have similar latency for zapping weak references that are
> used in the similarly shaped data structures.
>
> Allen
>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to