macos: fix small memory leak in surface tree when closing splits

This fixes a small memory leak I found where the `SplitNode.Leaf` was
not being deinitialized properly when closing a split. It would get
deinitialized the next time a split was made or the window was closed,
so the leak wasn't big. The surface view underneath the split was also
properly deinitialized because we forced it, so again, the leak was
quite small.

But conceptually this is a big problem, because when we change the
surface tree we expect the deinit chain to propagate properly through
the whole thing, _including_ to the SurfaceView.

This fixes that by removing the `id(node)` call. I don't find this to be
necessary anymore. I don't know when that happened but we've changed
quite a lot in our split system since it was introduced. I'm also not
100% sure why the `id(node)` was causing a strong reference to begin
with... which bothers me a bit.

AI note: While I manually hunted this down, I started up Claude Code and
Codex in separate tabs to also hunt for the memory leak. They both
failed to find it and offered solutions that didn't work.
This commit is contained in:
Mitchell Hashimoto
2025-06-02 13:57:33 -07:00
parent 957ddd00dd
commit d1f1be8833
4 changed files with 7 additions and 33 deletions

View File

@@ -102,19 +102,6 @@ extension Ghostty {
}
}
/// Close the surface associated with this node. This will likely deinitialize the
/// surface. At this point, the surface view in this node tree can never be used again.
func close() {
switch (self) {
case .leaf(let leaf):
leaf.surface.close()
case .split(let container):
container.topLeft.close()
container.bottomRight.close()
}
}
/// Returns true if any surface in the split stack requires quit confirmation.
func needsConfirmQuit() -> Bool {
switch (self) {
@@ -224,7 +211,7 @@ extension Ghostty {
self.app = app
self.surface = SurfaceView(app, baseConfig: baseConfig, uuid: uuid)
}
// MARK: - Hashable
func hash(into hasher: inout Hasher) {