Fix memory leaks in Promise whenAll#1016
Merged
designatednerd merged 2 commits intoapollographql:masterfrom Feb 13, 2020
Merged
Fix memory leaks in Promise whenAll#1016designatednerd merged 2 commits intoapollographql:masterfrom
designatednerd merged 2 commits intoapollographql:masterfrom
Conversation
Contributor
designatednerd
left a comment
There was a problem hiding this comment.
One question but THANK YOU for looking into this.
| waitForExpectations(timeout: 1) | ||
|
|
||
| XCTAssertNil(weakPromise0) | ||
| XCTAssertNil(weakPromise1) |
Contributor
There was a problem hiding this comment.
So before this fix, this particular assert would fail, correct?
Contributor
Author
There was a problem hiding this comment.
Actually, all three of the asserts were failing. The notify block references the entire array of promises, so all of them are retained.
Contributor
There was a problem hiding this comment.
oof, ouch. well this is definitely an improvement.
designatednerd
approved these changes
Feb 13, 2020
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 thenotifyblock was never being scheduled. This is what we wanted, but the unintended consequence of that is that thenotifyblock was then retained indefinitely, and thegroup.notifyblock is retaining thepromisesor 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.