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

The memory leak likely leads to performance degradations and crashes.
@dcalhoun dcalhoun added [Type] Bug Posting/Editing Gutenberg Editing and display of Gutenberg blocks. labels Oct 10, 2025
Copy link

@dcalhoun dcalhoun added this to the 26.5 milestone Oct 10, 2025
@wpmobilebot
Copy link
Contributor

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 Number29457
VersionPR #24936
Bundle IDcom.jetpack.alpha
Commitd7071d7
Installation URL5jtepeg1id7vg
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot
Copy link
Contributor

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 Number29457
VersionPR #24936
Bundle IDorg.wordpress.alpha
Commitd7071d7
Installation URL7g3jch06u6qpo
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.

tearDownKeyboardObservers()

// Cancel any pending tasks
editorLoadingTask?.cancel()
Copy link
Contributor

Choose a reason for hiding this comment

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

This line won't do anything because editorLoadingTask retains self, so there is no way deinit can get called before the task finishes.

editorLoadingTask?.cancel()

// Clean up child view controller
editorViewController.willMove(toParent: nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like a no-op as it happens automatically when the parent is removed.

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