Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory leaks in Promise whenAll #1016

Merged
merged 2 commits into from
Feb 13, 2020

Conversation

AnthonyMDev
Copy link
Contributor

When any of the promises reject, we were calling reject, but never leaving the DispatchGroup. This means the notify block was never being scheduled. This is what we wanted, but the unintended consequence of that is that the notify block was then retained indefinitely, and the group.notify block is retaining the promises or the resultOrPromises. This way, the notify block gets called and releases it's reference to the promises, but if any rejects occured, it does not call fulfill.

@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 for ResultOrPromise. I tested the fix with my app, and the memory leaks are gone now.

Copy link
Contributor

@designatednerd designatednerd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question but THANK YOU for looking into this.

waitForExpectations(timeout: 1)

XCTAssertNil(weakPromise0)
XCTAssertNil(weakPromise1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So before this fix, this particular assert would fail, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, all three of the asserts were failing. The notify block references the entire array of promises, so all of them are retained.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oof, ouch. well this is definitely an improvement.

@designatednerd designatednerd added this to the 0.23.0 milestone Feb 13, 2020
@designatednerd designatednerd merged commit 802624e into apollographql:master Feb 13, 2020
@AnthonyMDev AnthonyMDev deleted the whenAll-memory-leaks branch February 13, 2020 23:06
@AnthonyMDev AnthonyMDev restored the whenAll-memory-leaks branch February 13, 2020 23:06
@AnthonyMDev AnthonyMDev deleted the whenAll-memory-leaks branch March 23, 2021 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants