Skip to content

Commit bf8aded

Browse files
ADFA-3418: Tie IDEEditor's EventBus registration to its window
IDEEditor registered with the default EventBus in initEditor() and unregistered only in release(), which a recreate (dark mode, locale) never reaches, so EventBus kept each open editor and the destroyed activity (426 KB in a LeakCanary dump after the breakpoint-listener path was fixed). Register on attach and unregister on detach, as CodeEditorView does. Chosen over closing editors on recreate: close() posts DocumentCloseEvent through an async dispatcher, which could reach the language server after the recreated activity reopens the same file.
1 parent 483c84b commit bf8aded

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

  • editor/src/main/java/com/itsaky/androidide/editor/ui

‎editor/src/main/java/com/itsaky/androidide/editor/ui/IDEEditor.kt‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,8 +998,22 @@ open class IDEEditor
998998
selectionChangeHandler.postDelayed(it, SELECTION_CHANGE_DELAY)
999999
}
10001000
}
1001+
}
1002+
1003+
// EventBus follows the window, not release(): a recreate (dark mode, locale) destroys the
1004+
// activity without releasing its editors, and the default EventBus would keep them all.
1005+
override fun onAttachedToWindow() {
1006+
super.onAttachedToWindow()
1007+
if (!isReleased && !EventBus.getDefault().isRegistered(this)) {
1008+
EventBus.getDefault().register(this)
1009+
}
1010+
}
10011011

1002-
EventBus.getDefault().register(this)
1012+
override fun onDetachedFromWindow() {
1013+
super.onDetachedFromWindow()
1014+
if (EventBus.getDefault().isRegistered(this)) {
1015+
EventBus.getDefault().unregister(this)
1016+
}
10031017
}
10041018

10051019
// Inline suggestions (ghost text)

0 commit comments

Comments
 (0)