mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
fix: menu items not cleaned up after rebuild (#50832)
Menu was holding a SelfKeepAlive to itself from construction, so any Menu that was never opened (e.g. an application menu replaced before being shown) stayed pinned in cppgc forever. Repeated calls to Menu.setApplicationMenu leaked every prior Menu along with its model and items. Restore the original Pin/Unpin lifecycle: start keep_alive_ empty and only assign `this` in OnMenuWillShow. OnMenuWillClose already clears it. Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
@@ -276,6 +276,7 @@ void Menu::OnMenuWillClose() {
|
||||
}
|
||||
|
||||
void Menu::OnMenuWillShow() {
|
||||
keep_alive_ = this;
|
||||
Emit("menu-will-show");
|
||||
}
|
||||
|
||||
|
||||
@@ -132,7 +132,7 @@ class Menu : public gin::Wrappable<Menu>,
|
||||
int GetIndexOfCommandId(int command_id) const;
|
||||
int GetItemCount() const;
|
||||
|
||||
gin_helper::SelfKeepAlive<Menu> keep_alive_{this};
|
||||
gin_helper::SelfKeepAlive<Menu> keep_alive_{nullptr};
|
||||
};
|
||||
|
||||
} // namespace electron::api
|
||||
|
||||
Reference in New Issue
Block a user