fix: remove cyclic references of BrowserWindow (#22006)

* fix: remove cyclic references in BrowserWindow

* fix: prevent TopLevelWindow from garbage collection

* test: garbage collection of BrowserWindow

* chore: createIDWeakMap is used in tests
This commit is contained in:
Cheng Zhao 2020-02-11 09:37:46 +09:00 committed by GitHub
parent 9942149f3c
commit 9ad6f06831
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 76 additions and 32 deletions

View file

@ -120,6 +120,9 @@ TopLevelWindow::~TopLevelWindow() {
// Destroy the native window in next tick because the native code might be
// iterating all windows.
base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, window_.release());
// Remove global reference so the JS object can be garbage collected.
self_ref_.Reset();
}
void TopLevelWindow::InitWith(v8::Isolate* isolate,
@ -135,6 +138,9 @@ void TopLevelWindow::InitWith(v8::Isolate* isolate,
DCHECK(!parent.IsEmpty());
parent->child_windows_.Set(isolate, weak_map_id(), wrapper);
}
// Reference this object in case it got garbage collected.
self_ref_.Reset(isolate, wrapper);
}
void TopLevelWindow::WillCloseWindow(bool* prevent_default) {