LibWeb: Make Agent's MutationObserver list weak

Before this change, Agent held on to all of the live MutationObserver
objects via GC::Root. This prevented them from ever getting
garbage-collected.

Instead of roots, we now use a simple IntrusiveList and remove them
from it in the finalizer for MutationObserver.

This fixes a massive GC leak on Speedometer.
This commit is contained in:
Andreas Kling 2025-02-07 11:22:11 +01:00 committed by Andreas Kling
commit 53c9c6f3ee
Notes: github-actions[bot] 2025-02-07 15:54:21 +00:00
4 changed files with 14 additions and 6 deletions

View file

@ -10,6 +10,7 @@
#include <AK/Vector.h>
#include <LibGC/Root.h>
#include <LibJS/Forward.h>
#include <LibWeb/DOM/MutationObserver.h>
#include <LibWeb/Forward.h>
#include <LibWeb/HTML/CustomElements/CustomElementReactionsStack.h>
@ -25,8 +26,7 @@ struct Agent {
bool mutation_observer_microtask_queued { false };
// https://dom.spec.whatwg.org/#mutation-observer-list
// FIXME: This should be a set.
Vector<GC::Root<DOM::MutationObserver>> mutation_observers;
DOM::MutationObserver::List mutation_observers;
// https://html.spec.whatwg.org/multipage/custom-elements.html#custom-element-reactions-stack
// Each similar-origin window agent has a custom element reactions stack, which is initially empty.