-
Notifications
You must be signed in to change notification settings - Fork 114
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
POS: Fix retain cycles related to payment onboarding view #15083
Merged
staskus
merged 7 commits into
trunk
from
fix/14593-fix-pos-aggregate-modal-memory-leak-2
Feb 7, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5d4e4eb
Break a strong reference cycle where onboardingViewModel.showSupport …
staskus 74956ee
Capture POSAggregateModel in card connection Tasks weakly to release …
staskus 42643d3
Merge branch 'trunk' into fix/14593-fix-pos-aggregate-modal-memory-le…
staskus 434f8fe
Remove a retain cycle within CardPresentPaymentsOnboardingViewModel
staskus 4b16658
Break a reference cycle between POSAggregateModel and CardPresentPaym…
staskus 5c39bca
Don't hold CardPresentPaymentsOnboardingViewModel within CardPresentP…
staskus 43c2942
Merge branch 'trunk' into fix/14593-fix-pos-aggregate-modal-memory-le…
staskus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,9 @@ final class CardPresentPaymentsOnboardingViewModel: ObservableObject, PaymentSet | |
self?.updateLearnMoreURL(state: result) | ||
self?.reevaluateShouldShow(onboardingState: result) | ||
}) | ||
.handleEvents(receiveOutput: trackState(_:)) | ||
.handleEvents(receiveOutput: { [weak self] state in | ||
self?.trackState(state) | ||
}) | ||
Comment on lines
+36
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a great catch, it's not obvious at all that this captures self. I know it does, but it doesn't stand out. |
||
.assign(to: &$state) | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Does this really form part of a retain cycle? We don't retain the
Task
, so I'm not sure why this is needed...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.
Tasks are not released until the asynchronous work inside it finishes.
As I tested,
attemptConnection
never finishes when onboarding is opened and closed.Task
is not released until theconnectReader
finishes and it doesn't finish. SinceTask
retainsself
through accessingcardPresentPaymentService
,self
(PointOfSaleAggregateModel
) remains retained.Task.weak.self.720p.mov
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.
That's tricky to "visually" catch, as there are no explicit references to
self
. Thanks for the work on this and the explanation!