Skip to content

Conversation

dcalhoun
Copy link
Member

@dcalhoun dcalhoun commented Oct 10, 2025

Description

Close CMM-834.

It appears the strong Autosaver references and, possibly, lack of cleaning up asset loading tasks and view elements led to a retain cycle. The retain cycle prevented proper disposal of WebViews. The memory leak likely leads to performance degradations and crashes.

Testing instructions

1. Verify pending changes are persisted via autosave mechanism

  1. Open the GutenbergKit editor for a new or existing post.
  2. Make content changes—required to rigger autosaver.
  3. Attempt saving changes as well as closing the editor with pending changes.
  4. Verify new changes are persisted as expected.

2. Verify WebViews are disposed upon editor close

  1. Open the GutenbergKit editor.
  2. Insert content—required to rigger autosaver.
  3. Close the editor and discard/save changes.
  4. Repeat a few times.
  5. Attempt to inspect the WebView via Safari developer tools.
  6. Verify WebViews are not retained after the editor closes.
Screenshot 2025-10-10 at 08 31 09

@dcalhoun dcalhoun added [Type] Bug Posting/Editing Gutenberg Editing and display of Gutenberg blocks. labels Oct 10, 2025
@dcalhoun dcalhoun added this to the 26.5 milestone Oct 10, 2025
@wpmobilebot
Copy link
Contributor

wpmobilebot commented Oct 10, 2025

App Icon📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack
ConfigurationRelease-Alpha
Build Number29562
VersionPR #24936
Bundle IDcom.jetpack.alpha
Commit35a0f0c
Installation URL1j37can62algg
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Oct 10, 2025

App Icon📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress
ConfigurationRelease-Alpha
Build Number29562
VersionPR #24936
Bundle IDorg.wordpress.alpha
Commit35a0f0c
Installation URL4reufcgd6eaf0
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@dcalhoun dcalhoun requested review from Copilot and kean October 10, 2025 14:35
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a memory leak in GutenbergKit by preventing a retain cycle that was preventing proper disposal of WebViews. The fix addresses strong reference cycles in the Autosaver and improves cleanup of view controllers and tasks during deinitialization.

  • Changed Autosaver closure to use weak self reference to break retain cycle
  • Added proper cleanup of loading tasks and child view controllers in deinit

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

The memory leak likely leads to performance degradations and crashes.
This is effectively a no-op as it already occurs via UIKit behavior.
Allow clean up while the editor closes.
@dcalhoun dcalhoun force-pushed the fix/prevent-gutenberg-kit-retain-cycle branch from d7071d7 to 35a0f0c Compare October 20, 2025 19:10
Copy link

@dcalhoun dcalhoun requested a review from kean October 20, 2025 20:22
@kean
Copy link
Contributor

kean commented Oct 21, 2025

Approving the "autosaver" part, but I've noticed a couple of issues with loading dependencies. For example, it cancels the loading when you open "Revisions", and it also shows an infinite spinner when the dependencies fail load. I'll open a PR addressing these.

@dcalhoun dcalhoun added this pull request to the merge queue Oct 21, 2025
Merged via the queue into trunk with commit f165b6c Oct 21, 2025
30 of 32 checks passed
@dcalhoun dcalhoun deleted the fix/prevent-gutenberg-kit-retain-cycle branch October 21, 2025 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Gutenberg Editing and display of Gutenberg blocks. Posting/Editing [Type] Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants