From: Cheng Zhao Date: Fri, 27 Sep 2013 07:20:55 +0000 (+0800) Subject: Free the native window's memory after the event were sent for all observers. X-Git-Tag: v0.5.2~5 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=54b0d0c9c0ff351a6bcb6821a46b85e3bb2b457f;p=electron.git Free the native window's memory after the event were sent for all observers. If we delete the window immediately other observers may get a invalid window and cause random crashes. --- diff --git a/browser/api/atom_api_window.cc b/browser/api/atom_api_window.cc index 64ee74b9..8d1cd0a6 100644 --- a/browser/api/atom_api_window.cc +++ b/browser/api/atom_api_window.cc @@ -61,8 +61,9 @@ void Window::WillCloseWindow(bool* prevent_default) { void Window::OnWindowClosed() { Emit("closed"); - // Free memory immediately when window is closed. - delete this; + // Free memory when native window is closed, the delete is delayed so other + // observers would not get a invalid pointer of NativeWindow. + base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); } void Window::OnWindowBlur() {