Browse Source

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.
Andreas Kling 8 months ago
parent
commit
1510c1876c
1 changed files with 5 additions and 1 deletions
  1. 5 1
      Services/WebContent/ConnectionFromClient.cpp

+ 5 - 1
Services/WebContent/ConnectionFromClient.cpp

@@ -11,6 +11,7 @@
 
 #include <AK/JsonObject.h>
 #include <AK/QuickSort.h>
+#include <LibCore/EventLoop.h>
 #include <LibGfx/Bitmap.h>
 #include <LibGfx/Font/FontDatabase.h>
 #include <LibGfx/SystemTheme.h>
@@ -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;
     }