Garbage collection in generators

Benjamin Gruenbaum benjamingr at
Wed Feb 17 08:08:27 UTC 2016

In the following example:


function* foo() {
    try {
       yield 1;
    } finally {
(function() {
  var f = foo();;
  // never reference f again


 - Is the iterator created by the function `foo` ever eligible for garbage
 - If it is - does it run the `finally` blocks?

Related resources:

 - Python changed the behavior to "run `return` on gc" in 2.5
 - C# doesn't run finalizers, but iterators are disposable and get aborted
automatically by foreach (for... of) - on break. this is similar to what we
 - PHP is debating this issue now, I was contacted by PHP internals people
about it which is how I came into the problem in the first place:
 - Related issue I opened on async/await :
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list