-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
[swift5] URLSession: Fix memory leak of SessionDelegate #8558
[swift5] URLSession: Fix memory leak of SessionDelegate #8558
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.
Looks good to me.
Thanks for your contribution.
@@ -126,6 +124,7 @@ private var urlSessionStore = SynchronizedDictionary<String, URLSession>() | |||
} | |||
|
|||
let cleanupRequest = { | |||
urlSessionStore[urlSessionId]?.finishTasksAndInvalidate() |
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.
Interesting, I didn't know this API.
Can you please comment on the need of this?
Just curious.
Thanks 😊
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.
This invalidates the session after the all tasks of this session have completely finished. New tasks cannot be started on this session.
This call is not necessary, but good practice, since we're creating a session for each request, so after a task as finished we don't need the session anymore.
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.
Nice, thanks 👍
For me it's ready to merge 👍 |
cleanupRequest()
is only called on error for now. SosessionDelegate
doesn't get deallocated after request.I think it's okay to call
cleanupRequest()
directly after the processing of the response, instead of putting it in the completion closure, since it will only deallocate when not in use anymore. What do you guys think?PR checklist
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*
.For Windows users, please run the script in Git BASH.
master
,5.1.x
,6.0.x