Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MacOS: closing windows by clicking red X leaks surfaces #366

Closed
goonzoid opened this issue Aug 31, 2023 · 2 comments · Fixed by #375
Closed

MacOS: closing windows by clicking red X leaks surfaces #366

goonzoid opened this issue Aug 31, 2023 · 2 comments · Fixed by #375
Labels

Comments

@goonzoid
Copy link
Member

Closing windows via the keyboard shortcuts or exiting the shell process works fine, but clicking the red X on the title bar doesn't seem to result in ghostty_surface_free getting called, and so the shell keeps running without a visible surface or window!

@mitchellh
Copy link
Contributor

Note that SwiftUI retains one surface at all times, are you sure you're not seeing that? I haven't figured out why it does that, either, but it never should be more than one. I'm just asking this off the cuff...

@goonzoid
Copy link
Member Author

Pretty certain: here's Ghostty's process tree right now with 0 windows open after I closed 4 windows via clicking:
Screenshot 2023-08-30 at 22 12 16

Screenshot in iTerm because sometimes using a tool to debug itself is just a bit too cumbersome!

mitchellh added a commit that referenced this issue Sep 1, 2023
Fixes #366

The comment in the Swift code explains what was happening here:

> I don't know if this is the right place, but because of WindowAccessor in our
> SwiftUI hierarchy, we have a reference cycle between view and window and windows
> are never freed. When the window is closed, the window controller is deinitialized,
> so we can use this opportunity detach the view from the window and break the cycle.

An alternate solution would be to make our reference back to the window
"weak" but we appear to not be able to do that with SwiftUI property
wrappers such as `@State` and `@Binding` and so on.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants