Fix memory leaks in Promise whenAll #1016
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When any of the promises reject, we were calling reject, but never leaving the
DispatchGroup
. This means thenotify
block was never being scheduled. This is what we wanted, but the unintended consequence of that is that thenotify
block was then retained indefinitely, and thegroup.notify
block is retaining thepromises
or theresultOrPromises
. This way, the notify block gets called and releases it's reference to thepromises
, but if any rejects occured, it does not callfulfill
.@designatednerd I was seeing memory leaks in my application and was able to track it down to this. I wrote a unit test for
Promise
, but unit testing memory leaks of value semantic entities is impossible, so I can't provide a unit test forResultOrPromise
. I tested the fix with my app, and the memory leaks are gone now.