diff --git a/macos/Sources/Ghostty/Surface View/SurfaceView_AppKit.swift b/macos/Sources/Ghostty/Surface View/SurfaceView_AppKit.swift index afb7b0e9b..272f16e5a 100644 --- a/macos/Sources/Ghostty/Surface View/SurfaceView_AppKit.swift +++ b/macos/Sources/Ghostty/Surface View/SurfaceView_AppKit.swift @@ -292,7 +292,13 @@ extension Ghostty { // A drag can emit multiple selection changes. Debounce so screen // readers hear one announcement once the selection settles. accessibilitySelectionCancellable = NotificationCenter.default - .publisher(for: .ghosttySelectionDidChange, object: self) + // The publisher retains its object, so filtering with a weak capture + // avoids a cycle between self and the stored cancellable. + .publisher(for: .ghosttySelectionDidChange) + .filter { [weak self] notification in + guard let self else { return false } + return notification.object as AnyObject? === self + } .debounce(for: .milliseconds(100), scheduler: DispatchQueue.main) .sink { [weak self] _ in guard let self else { return }