-
Notifications
You must be signed in to change notification settings - Fork 948
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] NSWindow
s are not release
d when closed, causing odd zombie window behaviour in some cases.
#158
Comments
I can confirm this is a large problem with my setup, I'm using winit for vst plugin guis and it causes a bug where you cannot properly close the window. Also if you force a close and switch to another app then back, you get the same 'zombie' window described above. I get the feeling that winit is just leaking memory through dangling window refs on mac and has been since it was created... is this true? I tried the possible solution @mitchmindtree suggested above on my own fork, but instead created my own wrapper struct called |
After #476, windows can no longer close without being dropped (barring anything unexpected happening on the OS end). This stops the closed window from receiving events, but I can still get the zombie window to appear. Changing |
I won't get a chance to test this again myself for a while, but I'm happy for this to be closed if you are confident you can no longer reproduce this @francesca64. Thanks! |
1/3 reduction in binary size for `canvas_minimal`. Closes rust-windowing#158.
In the constructor for
Window
, the followingNSWindow
method is called:Instead, we rely on the
Drop
implementation forIdRef
to release theNSWindow
afterWindow
's drop method is called:In most cases this is fine, as a window is normally dropped immediately after it is closed. However, in some multi-window applications (like the
multiwindow.rs
example), aWindow
is not dropped until allWindow
s are closed. This means a user might have many windows that are "closed" but have not beenrelease
d.Documentation on what it means to have a "closed yet not released" window is quite sparse, however after doing some experiments it seems that cocoa does not handle this well. For example, when running the
multiwindow.rs
example, the following strange behaviour occurs:Click one of the windows to focus it.
Close that window via the x button.
Swipe sideways to switch to a separate desktop. This causes a
Focus(false)
event to be produced for the window that was just closed. We shouldn't receive any events for the window that was just closed.Swipe back to the original desktop. This causes a
Focus(true)
event to be produced for the window that was closed and causes it to reappear (though without its toolbar)!Click one of the other windows to focus it.
Close the window via the x button.
Swipe sideways to a different desktop (again causing a
Focus(false)
event to be produced for the window we just closed).Swipe back to the original desktop. Not only does the window we just closed reappear, now the first window we closed regains its toolbar again!
If we we run this experiment again after changing
window.setReleasedWhenClosed_(NO);
's input toYES
, it seems to run perfectly without any zombie windows reappearing right until the last window is closed and the example segfaults. The segfault occurs at themsg_send![self.0, release]
line inIdRef
'sDrop
implementation, right after theWindowDelegate
'sDrop
implementation is run.This crash likely occurs due to attempting to release the
NSWindow
after it has already been automatically released followingClosed
.Possible Solution
Perhaps we could solve this by switching
window.setReleasedWhenClosed_(NO);
's input toYES
and store a regularcocoa::base::id
for theNSWindow
rather than anIdRef
? It seems likeIdRef
was added as a method to automatically clean up objects that would normally require the user to manuallyrelease
them, however in this case theNSWindow
could do its own cleanup when closed, so it seemsIdRef
should not be necessary?I'll do some more reading and see if I can find any more information before settling on this, but it seems like it might be the best option for now.
The text was updated successfully, but these errors were encountered: