- From: Andrea Giammarchi <notifications@github.com>
- Date: Wed, 01 Apr 2015 07:06:37 -0700
- To: whatwg/fetch <fetch@noreply.github.com>
- Message-ID: <whatwg/fetch/issues/27/88497015@github.com>
Agreed it'd be handy to have cancelable chain but I also agree for simplicity sake my latest playground with no chain at all might work as well, providing the ability to eventually monkey patch on top without somehow encouraging cancelability as default pattern. It's still unclear, since apparently non cancelable promises should throw, what would be the behavior of Promise.all().cancel() ...maybe that's also not needed in core... On Apr 1, 2015 3:56 PM, "Marius Gundersen" <notifications@github.com> wrote: > One issue with canceling an entire chain is that it could leak memory. > Currently a pending promise can be garbage collected if nothing in > referencing it. In the chain c = a.then(() => b), a can be garbage > collected because neither b nor c hold a reference to it (a holds a > reference to c). > > With cancellation there needs to be a reference in both directions, so c > needs to have a reference to a so it can cancel a. > > This isn't a very big issue though, since c can drop it's reference to a > the moment it is cancelled or resolved (by a), thereby breaking the > reference chain. This means that there will only be a memory leak for > forever pending promises: > > var neverResolving = new Promise(r => 'I never resolve');var leaker = neverResolving.then(a => 'I hold on to neverResolving'); > neverResolving = null;//if leaker is a normal promise, neverResolving will now be garbage collected.//if leaker is a cancellable promise, neverResolving will not be garbage collected until leaker is! > > Since this is only an issue with promises that never resolve, I don't > think it is much to worry about. > > — > Reply to this email directly or view it on GitHub > <https://github.com/whatwg/fetch/issues/27#issuecomment-88489237>. > --- Reply to this email directly or view it on GitHub: https://github.com/whatwg/fetch/issues/27#issuecomment-88497015
Received on Wednesday, 1 April 2015 14:07:03 UTC