diff --git a/src/cg.rs b/src/cg.rs index 1309a43..54573fe 100644 --- a/src/cg.rs +++ b/src/cg.rs @@ -22,6 +22,7 @@ pub struct CGImpl { impl CGImpl { pub unsafe fn new(handle: AppKitWindowHandle) -> Result { let window = handle.ns_window as id; + let window: id = msg_send![window, retain]; let view = handle.ns_view as id; let layer = CALayer::new(); unsafe { @@ -71,3 +72,11 @@ impl CGImpl { transaction::commit(); } } + +impl Drop for CGImpl { + fn drop(&mut self) { + unsafe { + let _: () = msg_send![self.window, release]; + } + } +}