Skip to content
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

Fix retain cycle in GutenbergViewController #22265

Merged
merged 2 commits into from
Dec 25, 2023
Merged

Conversation

kean
Copy link
Contributor

@kean kean commented Dec 21, 2023

Fix some of the occurrences of #20647, namely the ones references in #20647 (comment).

RCA

PrepublishingViewController had a retain cycle "thanks" to assign(to:).

When "Tags" screen was presented this property was called for the first time:

private lazy var presentedVC: DrawerPresentationController? {
	return (navigationController as? PrepublishingNavigationController)?.presentedVC
}

I haven't followed the entire memory graph, but this property was evidently indirectly retaining the main GutenbergViewController. And because PrepublishingViewController had a retain cycle, it was also permanently retaining whatever was referenced by presentedVC.

To test:

Regression Testing

  • Verify that publishing and settings tags still work

Regression Notes

  1. Potential unintended areas of impact: Gutenberg
  2. What I did to test those areas of impact (or what existing automated tests I relied on): n/a
  3. What automated tests I added (or what prevented me from doing so): n/a

PR submission checklist:

  • I have completed the Regression Notes.
  • I have considered adding unit tests for my changes.
  • I have considered adding accessibility improvements for my changes.
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

UI Changes testing checklist:

  • Portrait and landscape orientations.
  • Light and dark modes.
  • Fonts: Larger, smaller and bold text.
  • High contrast.
  • VoiceOver.
  • Languages with large words or with letters/accents not frequently used in English.
  • Right-to-left languages. (Even if translation isn’t complete, formatting should still respect the right-to-left layout)
  • iPhone and iPad.
  • Multi-tasking: Split view and Slide over. (iPad)

@kean kean requested a review from alpavanoglu December 21, 2023 00:31
@kean kean added this to the 24.0 milestone Dec 21, 2023
@kean kean changed the title Fix retain cycle in GutenbergViewController and PrepublishingViewController Fix retain cycle in GutenbergViewController Dec 21, 2023
@wpmobilebot
Copy link
Contributor

wpmobilebot commented Dec 21, 2023

WordPress Alpha📲 You can test the changes from this Pull Request in WordPress Alpha by scanning the QR code below to install the corresponding build.
App NameWordPress Alpha WordPress Alpha
ConfigurationRelease-Alpha
Build Numberpr22265-b765975
Version23.9
Bundle IDorg.wordpress.alpha
Commitb765975
App Center BuildWPiOS - One-Offs #8237
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Dec 21, 2023

Jetpack Alpha📲 You can test the changes from this Pull Request in Jetpack Alpha by scanning the QR code below to install the corresponding build.
App NameJetpack Alpha Jetpack Alpha
ConfigurationRelease-Alpha
Build Numberpr22265-b765975
Version23.9
Bundle IDcom.jetpack.alpha
Commitb765975
App Center Buildjetpack-installable-builds #7261
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

Copy link
Contributor

@twstokes twstokes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM @kean! I couldn't reproduce the crash when following the steps in #20647 (comment). I was able to reproduce the crash using when rolling back to 4fc94b6. 🚀

@@ -133,13 +133,11 @@ class PrepublishingViewController: UITableViewController {
/// Toggles `keyboardShown` as the keyboard notifications come in
private func configureKeyboardToggle() {
NotificationCenter.default.publisher(for: UIResponder.keyboardDidShowNotification)
.map { _ in return true }
.assign(to: \.keyboardShown, on: self)
.sink { [weak self] _ in self?.keyboardShown = true }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make sure I understand it correctly: The cycle was due to passing directly self rather than using assign right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .assign(to: \.keyboardShown, on: self) method retains self, which is a common issue in Combine.

Copy link
Contributor

@alpavanoglu alpavanoglu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the fix Alex!

@kean kean force-pushed the fix/retain-cycle-in-gutenberg branch from a491f52 to b765975 Compare December 25, 2023 20:18
@peril-wordpress-mobile
Copy link

Warnings
⚠️ This PR is assigned to a milestone which is closing in less than 4 days Please, make sure to get it merged by then or assign it to a later expiring milestone

Generated by 🚫 dangerJS

@kean kean enabled auto-merge December 25, 2023 20:19
@wpmobilebot
Copy link
Contributor

1 Warning
⚠️ This PR is assigned to the milestone 24.0. The due date for this milestone has already passed.
Please make sure to get it merged by then or assign it to a milestone with a later deadline.

Generated by 🚫 Danger

@kean kean merged commit 1ae3a1a into trunk Dec 25, 2023
23 checks passed
@kean kean deleted the fix/retain-cycle-in-gutenberg branch December 25, 2023 21:01
@kean kean mentioned this pull request Dec 27, 2023
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants