-
Notifications
You must be signed in to change notification settings - Fork 734
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
Use weak references to Apollo client in closures #854
Use weak references to Apollo client in closures #854
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call on the closures, got a question on one thing though
@@ -206,7 +215,7 @@ private func wrapResultHandler<Data>(_ resultHandler: GraphQLResultHandler<Data> | |||
} | |||
|
|||
private final class FetchQueryOperation<Query: GraphQLQuery>: AsynchronousOperation, Cancellable { | |||
let client: ApolloClient | |||
weak var client: ApolloClient? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this need to be weak
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're adding the operation to the client's queue
apollo-ios/Sources/Apollo/ApolloClient.swift
Lines 137 to 138 in 509b222
let operation = FetchQueryOperation(client: self, query: query, cachePolicy: cachePolicy, context: context, resultHandler: resultHandler) | |
self.operationQueue.addOperation(operation) |
so both the client and the operation will be retained here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh woof, good point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
Anyone else who ends up here wondering why they're not getting any data back anymore... you're probably not holding onto a strong reference of the |
Ha, good catch! I'll make a note of it on the release notes for |
This PR changes a few closures that were keeping a strong reference to the Apollo client. This is to make sure that as soon as the user of Apollo client releases its reference, all Apollo operations will stop.