Skip to content

Commit ca5ccc5

Browse files
committed
fix: Prevent GutenbergKit retain cycle
The memory leak likely leads to performance degradations and crashes.
1 parent aa9c58b commit ca5ccc5

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

WordPress/Classes/ViewRelated/NewGutenberg/NewGutenbergViewController.swift

Lines changed: 10 additions & 2 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,14 @@ class NewGutenbergViewController: UIViewController, PostEditor, PublishingEditor
197197

198198
deinit {
199199
tearDownKeyboardObservers()
200+
201+
// Cancel any pending tasks
202+
editorLoadingTask?.cancel()
203+
204+
// Clean up child view controller
205+
editorViewController.willMove(toParent: nil)
206+
editorViewController.view.removeFromSuperview()
207+
editorViewController.removeFromParent()
200208
}
201209

202210
// MARK: - Lifecycle methods

0 commit comments

Comments
 (0)