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
[CIS-1522] Fix Memory Leaks when opening and closing channels #1812
[CIS-1522] Fix Memory Leaks when opening and closing channels #1812
Conversation
9f36b15
to
8f2fa1f
Compare
Codecov Report
@@ Coverage Diff @@
## develop #1812 +/- ##
===========================================
- Coverage 85.50% 85.37% -0.13%
===========================================
Files 234 234
Lines 11314 11333 +19
===========================================
+ Hits 9674 9676 +2
- Misses 1640 1657 +17
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
The `URLSession.delegate` is actually a strong reference. We need to call `invalidateAndCancel()` to make sure the session is deallocated. To make sure there is not ref cycle, we introduced a `URLSessionDelegateHandler` to break the cycle.
42d455a
to
2a590ff
Compare
2a590ff
to
b42762a
Compare
da5b7fe
to
26a8029
Compare
Sources/StreamChat/WebSocketClient/Engine/URLSessionWebSocketEngine.swift
Outdated
Show resolved
Hide resolved
Sources/StreamChat/WebSocketClient/Engine/URLSessionWebSocketEngine.swift
Show resolved
Hide resolved
Sources/StreamChat/WebSocketClient/Engine/URLSessionWebSocketEngine.swift
Show resolved
Hide resolved
@nuno-vieira codecov reports quite huge decrease in the test coverage. |
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.
LGTM ✅
@bielikb The code coverage is decrasing 0.13%, it is minimal. (From 85.50% to 85.37%). This PR has a 72% coverage, of which the min is 85%. The reason is because URLSessionWebSocketEngine is not tested at all. It wasn't before, and I don't think it is worth adding tests for it, since it is just a wrapper for URLSession. |
🔗 Issue Link
CIS-1522
🎯 Goal
The main goal was to fix the memory leaks around opening and closing channels which was mostly caused by the
GalleryVC
, but an overall cleanup of the memory leaks on the SDK was done as well.🛠 Implementation
Break reference cycles in multiple places of the codebase.
📝 Changes
URLSession
in theURLWebSocketEngine
. According to Apple, theURLSession.delegate
is strongly retained and we need to make sure we callinvalidateAndCancel()
to clean up theURLSession
.GalleryVC
.ChatClient
in theLoginViewController
so that is easier to analyse memory leaks🎨 Changes
These are the instances that are retained after playing with the application and then coming back to the login screen before the fixes and after the fixes.
🧪 Testing
☑️ Contributor Checklist
🎉 GIF