From: Cheng Zhao Date: Tue, 12 Jan 2016 13:10:24 +0000 (+0800) Subject: Destroy the native class when webContents is destroyed X-Git-Tag: v0.36.4~16^2~1 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=eb63e6b9a7f1db70be024987c34ec62ce75268f8;p=electron.git Destroy the native class when webContents is destroyed --- diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 43ce5562..4d449ed9 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -635,8 +635,16 @@ bool WebContents::OnMessageReceived(const IPC::Message& message) { void WebContents::WebContentsDestroyed() { // The RenderViewDeleted was not called when the WebContents is destroyed. RenderViewDeleted(web_contents()->GetRenderViewHost()); - Emit("destroyed"); RemoveFromWeakMap(); + + // We can not call Destroy here because we need to call Emit first, but we + // also do not want any method to be used, so just mark as destroyed here. + MarkDestroyed(); + + Emit("destroyed"); + + // Destroy the native class in next tick. + base::MessageLoop::current()->PostTask(FROM_HERE, GetDestroyClosure()); } void WebContents::NavigationEntryCommitted(