Weak References

Isiah Meadows isiahmeadows at gmail.com
Mon Sep 7 17:53:04 UTC 2015


It's replacing the prototype of a stream periodically to point to a new
writable file output stream pointing to a new file, but I want to kill the
interval timer when the object is garbage collected.

Something like this:

1. Create new stream.
2. Point it to a log file.
3. Every tick on a given interval, do this:
3.1. Change the destination of the stream to a new log file.
4. When the stream itself is GC'd, do this:
4.1. Clear the timer.
4.2. Clear all local references to both the timer and the stream.
5. Return the stream.

The catch is that I don't want the stream strongly referenced in any local
closures because it would end up never being collected - there would always
be an active strong reference to it. I don't think a
`Reflect.onOnlyOneReferenceLeft(obj, callback)` would make it into the
language, so weak references are the best way to avoid this. And if I were
doing this in Java or C++, I would most definitely use weak
references/pointers for this use case. (This is out of the land of what
automatic garbage collection can handle at this point.)

On Mon, Sep 7, 2015, 13:33 Mark S. Miller <erights at google.com> wrote:

> I also don't get the purpose of this code. What is it trying to achieve?
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150907/cfd611c8/attachment.html>


More information about the es-discuss mailing list