From 154a184c1bcad434f506065a775ae28e39e39b15 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 16 Aug 2020 20:35:03 +0200 Subject: [PATCH] Browser: Add a debug menu action for triggering a JS garbage collection Triggering a GC this way will print a report afterwards so you can see how much memory is currently used by the JS heap. :^) --- Applications/Browser/Tab.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Applications/Browser/Tab.cpp b/Applications/Browser/Tab.cpp index 38e8059a61..4c415325d9 100644 --- a/Applications/Browser/Tab.cpp +++ b/Applications/Browser/Tab.cpp @@ -361,6 +361,17 @@ Tab::Tab(Type type) line_box_borders_action->set_checked(false); debug_menu.add_action(line_box_borders_action); + debug_menu.add_separator(); + debug_menu.add_action(GUI::Action::create("Collect garbage", { Mod_Ctrl | Mod_Shift, Key_G }, [this](auto&) { + if (m_type == Type::InProcessWebView) { + if (auto* document = m_page_view->document()) { + document->interpreter().heap().collect_garbage(JS::Heap::CollectionType::CollectGarbage, true); + } + } else { + TODO(); + } + })); + auto& bookmarks_menu = m_menubar->add_menu("Bookmarks"); bookmarks_menu.add_action(WindowActions::the().show_bookmarks_bar_action());