Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[6.0] Fix a memory leak in
DownloadTaskManager
and DataTaskManager
(
#7416) * **Explanation**: `DownloadTaskManager` had a strong reference to `URLSession`, which retained its delegate, which was the `DownloadTaskManager`. This formed a retain cycle. Make the reference from `URLSession` to the delegate weak and only keep `DownloadTaskManager` alive as long as `DownloadTask`s need it. This causes the `DownloadTaskManager` to be deallocated once nobody holds a reference to it anymore and all the tasks it manages are finished. Finally, we need to call `invalidate` on the `URLSession` to tell it that we’re done and that it should release its delegate (which is now the `WeakDownloadTaskManager` wrapper). This retain cycle was causing a leak in sourcekit-lsp. I verified that the leak no longer exists with this patch. * **Scope**: The change should be transparent to all users of `DataTaskManager` and `DownloadTaskManager` and only prevent the memory leak * **Risk**: I don’t see a risk with this change since the `{Data|Download}TaskManager` is kept alive as long as there is anything left that might call it. * **Testing**: I verified that the leak no longer exists with this patch. * **Issue**: rdar://125012584 * **Reviewer**: @MaxDesiatov on #7408
- Loading branch information
Showing
1 changed file
with
123 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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