From 1510c1876c023de977bf5b028672e61336761176 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 10 Nov 2024 15:14:12 +0100 Subject: [PATCH] WebContent: Try to run manual GC with less stuff on the stack This makes it more likely to succeed in collecting stuff that's actually dead, by reducing the memory range scanned for possible pointers. --- Services/WebContent/ConnectionFromClient.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Services/WebContent/ConnectionFromClient.cpp b/Services/WebContent/ConnectionFromClient.cpp index a6ad03e77cc..3b9f96db650 100644 --- a/Services/WebContent/ConnectionFromClient.cpp +++ b/Services/WebContent/ConnectionFromClient.cpp @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -354,7 +355,10 @@ void ConnectionFromClient::debug_request(u64 page_id, ByteString const& request, } if (request == "collect-garbage") { - Web::Bindings::main_thread_vm().heap().collect_garbage(JS::Heap::CollectionType::CollectGarbage, true); + // NOTE: We use deferred_invoke here to ensure that GC runs with as little on the stack as possible. + Core::deferred_invoke([] { + Web::Bindings::main_thread_vm().heap().collect_garbage(JS::Heap::CollectionType::CollectGarbage, true); + }); return; }