Skip to content

Commit f165b6c

Browse files
authored
fix: Prevent GutenbergKit retain cycle (#24936)
* fix: Prevent GutenbergKit retain cycle The memory leak likely leads to performance degradations and crashes. * refactor: Remove redundant view controller clean up This is effectively a no-op as it already occurs via UIKit behavior. * fix: Editor loading allows deinit with weak self references Allow clean up while the editor closes.
1 parent aa9c58b commit f165b6c

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

WordPress/Classes/ViewRelated/NewGutenberg/NewGutenbergViewController.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ class NewGutenbergViewController: UIViewController, PostEditor, PublishingEditor
113113
private var hasEditorStarted = false
114114
private var isModalDialogOpen = false
115115

116-
lazy var autosaver = Autosaver() {
117-
self.performAutoSave()
116+
lazy var autosaver = Autosaver() { [weak self] in
117+
self?.performAutoSave()
118118
}
119119

120120
// MARK: - Private Properties
@@ -197,6 +197,9 @@ class NewGutenbergViewController: UIViewController, PostEditor, PublishingEditor
197197

198198
deinit {
199199
tearDownKeyboardObservers()
200+
201+
// Cancel any pending tasks
202+
editorLoadingTask?.cancel()
200203
}
201204

202205
// MARK: - Lifecycle methods
@@ -247,7 +250,8 @@ class NewGutenbergViewController: UIViewController, PostEditor, PublishingEditor
247250
preconditionFailure("Dependency loading should not be cancelled")
248251
}
249252

250-
self.editorLoadingTask = Task {
253+
self.editorLoadingTask = Task { [weak self] in
254+
guard let self else { return }
251255
do {
252256
while case .loadingDependencies = self.editorState {
253257
try await Task.sleep(nanoseconds: 1000)

0 commit comments

Comments
 (0)