leebyron/iterall

forAwaitEach memory leak

NeoPhi opened this issue · 0 comments

The following program when run on node 8 shows unbounded memory growth. It looks to be related to nested promises and closures.

const iterall = require('iterall');

class Chirper {
  [iterall.$$asyncIterator]() {
    let num = 0;
    return {
      next() {
        return Promise.resolve({ value: num++, done: false });
      },
    };
  }
}

iterall.forAwaitEach(new Chirper(), function(value, index, iterable) {
  if (index % 100000 === 0) {
    console.log(value, index);
    console.log(process.memoryUsage());
  }
});