Garbage collection in generators
Andreas Rossberg
rossberg at google.com
Wed Feb 17 08:51:30 UTC 2016
On 17 February 2016 at 09:40, Benjamin Gruenbaum <benjamingr at gmail.com>
wrote:
> If you starve a generator it's not going to get completed, just like other
>> control flow won't.
>>
>
> I'm not sure starving is what I'd use here - I definitely do see users do
> a pattern similar to:
>
> ```js
> function getResults*() {
> try {
> var resource = acquire();
> for(const item of resource) yield process(item);
> } finally {
> release(resource);
> }
> }
> ```
>
Yes, exactly the kind of pattern I was referring to as "bogus forms of
resource management". This is an anti-pattern in ES6. It won't work
correctly. We should never have given the illusion that it does.
garbage collection is a form of automatic resource management.
Most GC experts would strongly disagree, if by resource you mean anything
else but memory.
/Andreas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160217/22fca0e2/attachment-0001.html>
More information about the es-discuss
mailing list