diff --git a/Services/WebContent/ConnectionFromClient.cpp b/Services/WebContent/ConnectionFromClient.cpp index a6ad03e77c..3b9f96db65 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; }