From 9c54bd1bd4afe7f19113e896b041dd79d14fd8d6 Mon Sep 17 00:00:00 2001 From: Thorsten Ball Date: Wed, 9 Oct 2024 10:45:35 +0200 Subject: [PATCH] macOS: Drop input handler to avoid editor/project not being dropped (#18898) This fixes the problem of a `Project` sometimes not being dropped when closing the single, last window of Zed. Turns out, it wasn't get dropped for the following reason: 1. `editor::Editor` held a reference to project 2. The macOS `input_handler` on the `Window` held a reference to that `Editor` 3. The AppKit window (and its input handler) get dropped asynchronously (in the code in this diff), after the window is closed. 4. After the window is closed and no `cx.update()` calls are made anymore, `flush_effects` is not called anymore. 5. But `flush_effects` is where we dropped entities that don't have any more references. In short: we dropped `Editor`, which held a reference to `Project`, out of band, `flush_effects` wasn't called anymore, and thus the `Project` wasn't dropped. cc @ConradIrwin @bennetbo since we talked about this. Release Notes: - N/A Co-authored-by: Antonio --- crates/gpui/src/platform/mac/window.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/gpui/src/platform/mac/window.rs b/crates/gpui/src/platform/mac/window.rs index 5f9ee43dec48f..6d887f2b1384f 100644 --- a/crates/gpui/src/platform/mac/window.rs +++ b/crates/gpui/src/platform/mac/window.rs @@ -768,6 +768,7 @@ impl Drop for MacWindow { unsafe { this.native_window.setDelegate_(nil); } + this.input_handler.take(); this.executor .spawn(async move { unsafe {