Skip to content

Commit

Permalink
macos: fix leak of Window and View objects
Browse files Browse the repository at this point in the history
  • Loading branch information
0f-0b authored and wez committed Oct 30, 2023
1 parent 453ff8d commit 4551903
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions window/src/os/macos/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,7 @@ impl Window {
let _: () = msg_send![*window, setRestorable: NO];

window.setReleasedWhenClosed_(NO);
let ns_color: id = msg_send![Class::get("NSColor").unwrap(), alloc];
window.setBackgroundColor_(cocoa::appkit::NSColor::clearColor(ns_color));
window.setBackgroundColor_(cocoa::appkit::NSColor::clearColor(nil));

// We could set this, but it makes the entire window, including
// its titlebar, opaque to this fixed degree.
Expand Down Expand Up @@ -1734,15 +1733,6 @@ impl WindowView {
}
}

/// `dealloc` is called when our NSView descendant is destroyed.
/// In practice, I've not seen this trigger, which likely means
/// that there is something afoot with reference counting.
/// The cardinality of Window and View objects is low enough
/// that I'm "OK" with this for now.
/// What really matters is that the `Inner` object is dropped
/// in a timely fashion once the window is closed, so we manage
/// that by hooking into `windowWillClose` and routing both
/// `dealloc` and `windowWillClose` to `drop_inner`.
fn drop_inner(this: &mut Object) {
unsafe {
let myself: *mut c_void = *this.get_ivar(VIEW_CLS_NAME);
Expand Down Expand Up @@ -2124,10 +2114,10 @@ impl WindowView {
.events
.dispatch(WindowEvent::Destroyed);
this.update_application_presentation(false);
let conn = Connection::get().unwrap();
let window_id = this.inner.borrow_mut().window_id;
conn.windows.borrow_mut().remove(&window_id);
}

// Release and zero out the inner member
Self::drop_inner(this);
}

fn mouse_common(this: &mut Object, nsevent: id, kind: MouseEventKind) {
Expand Down

0 comments on commit 4551903

Please sign in to comment.