Skip to content

Commit

Permalink
fix: prevent memory leak on macOS, closes #536
Browse files Browse the repository at this point in the history
  • Loading branch information
keiya01 committed May 15, 2022
1 parent e11ad09 commit 2b2eb6d
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/webview/wkwebview/mod.rs
Expand Up @@ -476,6 +476,9 @@ r#"Object.defineProperty(window, 'ipc', {
let ns_window = window.ns_window() as id;
let _: () = msg_send![ns_window, setContentView: webview];

let interop = NSString::new("interop");
let _: () = msg_send![manager, addScriptMessageHandler:webview name:interop];

// make sure the window is always on top when we create a new webview
let app_class = class!(NSApplication);
let app: id = msg_send![app_class, sharedApplication];
Expand Down Expand Up @@ -650,6 +653,10 @@ impl Drop for InnerWebView {
// So we need to override the process by navigating to `about:blank`.
self.navigate("about:blank");

// To prevent memory leak, we need to remove webview by script message handler.
let interop = NSString::new("interop");
let _: () = msg_send![self.manager, removeScriptMessageHandlerForName: interop];

let _: Id<_> = Id::from_ptr(self.webview);
#[cfg(target_os = "macos")]
let _: Id<_> = Id::from_ptr(self.ns_window);
Expand Down

0 comments on commit 2b2eb6d

Please sign in to comment.