Re: Garbage collection in generators

2016-02-17 Thread Boris Zbarsky
On 2/17/16 3:59 AM, Benjamin Gruenbaum wrote: Garbage collection can and does in fact manage resources in JavaScript host environments right now. For example, an XMLHttpRequest /may /abort the underlying HTTP request if the XMLHttpObject is not referenced anywhere and gets garbage collected.

Re: Garbage collection in generators

2016-02-17 Thread Benjamin Gruenbaum
> C++ RAII and Python refcounting are completely different: they are precise, prompt, predictable, and deterministic. C++ RAII is indeed amazingly deterministic - as are languages with built in reference counters like Swift. Python refcounting certainly is not since it performs cycle detection.

Re: Garbage collection in generators

2016-02-17 Thread Mark S. Miller
Everyone, please keep in mind the following distinctions: General GC is not prompt or predicable. There is an unspecified and unpredictable delay before anything non-reachable is noticed to be unreachable. JavaScript GC is not specified to be precise, and so should be assumed conservative.

Re: Garbage collection in generators

2016-02-17 Thread Benjamin Gruenbaum
On Wed, Feb 17, 2016 at 10:51 AM, Andreas Rossberg wrote: > On 17 February 2016 at 09:40, Benjamin Gruenbaum > wrote: > >> If you starve a generator it's not going to get completed, just like >>> other control flow won't. >>> >> >> I'm not sure

Re: Garbage collection in generators

2016-02-17 Thread Andreas Rossberg
On 17 February 2016 at 09:40, Benjamin Gruenbaum 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 >

Re: Garbage collection in generators

2016-02-17 Thread Benjamin Gruenbaum
On Wed, Feb 17, 2016 at 10:28 AM, Andreas Rossberg wrote: > > The spec does not talk about GC, but in typical implementations you should > expect yes. > Yes, important point since some ECMAScript implementations don't even have GC and are just run to completion. The spec

Re: Garbage collection in generators

2016-02-17 Thread Andreas Rossberg
On 17 February 2016 at 09:08, Benjamin Gruenbaum wrote: > In the following example: > > ```js > > function* foo() { > try { >yield 1; > } finally { > cleanup(); > } > } > (function() { > var f = foo(); > f.next(); > // never reference f

Garbage collection in generators

2016-02-17 Thread Benjamin Gruenbaum
In the following example: ```js function* foo() { try { yield 1; } finally { cleanup(); } } (function() { var f = foo(); f.next(); // never reference f again })() ``` - Is the iterator created by the function `foo` ever eligible for garbage collection? - If