From db39910455bdfde133a982afc91c91903040e09e Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 23 Apr 2014 09:25:04 +0800 Subject: [PATCH] Remove window from observers when it's closed instead of deleted. --- atom/browser/api/atom_api_window.cc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index f3ad61bcd1..6c8544d8a1 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -75,8 +75,6 @@ Window::Window(base::DictionaryValue* options) Window::~Window() { Emit("destroyed"); - - window_->RemoveObserver(this); } void Window::OnPageTitleUpdated(bool* prevent_default, @@ -99,9 +97,13 @@ void Window::WillCloseWindow(bool* prevent_default) { void Window::OnWindowClosed() { Emit("closed"); - // 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, window_.release()); + if (window_) { + window_->RemoveObserver(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, window_.release()); + } } void Window::OnWindowBlur() {