]> khamidou — GitHub mirrors - electron.git/commitdiff
Free the native window's memory after the event were sent for all observers.
authorCheng Zhao <zcbenz@gmail.com>
Fri, 27 Sep 2013 07:20:55 +0000 (15:20 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Fri, 27 Sep 2013 07:24:03 +0000 (15:24 +0800)
If we delete the window immediately other observers may get a invalid
window and cause random crashes.

browser/api/atom_api_window.cc

index 64ee74b9f9d7bd267389dc27831b8a9af06e17eb..8d1cd0a66749ac18a4116d42dfe18ff4003f0c8c 100644 (file)
@@ -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() {