getify / CAF

Cancelable Async Flows (CAF)
MIT License
1.34k stars 46 forks source link

Possible improvement to memory cleanup in signal race/all combinators #20

Closed getify closed 4 years ago

getify commented 4 years ago

This twitter conversation gets me wondering about these lines, where we add an event listener to each parent for a child signal, but those event listeners are not removed (only the one that fires removes itself).

It might be useful for getSignalPr(..) to expose a trigger to call removeEventListener(..), so that lines 155 and 164 can remove the event handlers for all parent signals. That should ensure the promises for each child signal are GC'd, even though the child signals should already be able to be GC'd.

Also, it might be worth exploring if a WeakMap could possibly be more useful here or not, from the GC perspective.

getify commented 4 years ago

https://gist.github.com/getify/aef532057da25f934ce23f21c50c8d40