mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 01:35:08 +02:00
LibWeb: Unregister ResizeObserver from Document when it has no targets
According to the spec, `ResizeObserver` needs to live for as long as it's referenced from script or has observation targets. With this change we make sure that `ResizeObserver` is unregistered from the `Document` when it has no target. Fixes GC leak that caused us to keep all resize observers alive until document they belong to is destroyed.
This commit is contained in:
committed by
Andreas Kling
parent
40fd2643cc
commit
4cbf47dcd2
Notes:
github-actions[bot]
2025-07-29 22:56:18 +00:00
Author: https://github.com/kalenikaliaksandr Commit: https://github.com/LadybirdBrowser/ladybird/commit/4cbf47dcd2f Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5646
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2021, Andreas Kling <andreas@ladybird.org>
|
||||
* Copyright (c) 2024, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
||||
* Copyright (c) 2024-2025, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
@@ -44,6 +44,8 @@ private:
|
||||
virtual void visit_edges(JS::Cell::Visitor&) override;
|
||||
virtual void finalize() override;
|
||||
|
||||
void unregister_observer_if_needed();
|
||||
|
||||
GC::Ptr<WebIDL::CallbackType> m_callback;
|
||||
Vector<GC::Ref<ResizeObservation>> m_observation_targets;
|
||||
Vector<GC::Ref<ResizeObservation>> m_active_targets;
|
||||
@@ -51,6 +53,11 @@ private:
|
||||
|
||||
// AD-HOC: This is the document where we've registered the observer.
|
||||
WeakPtr<DOM::Document> m_document;
|
||||
|
||||
IntrusiveListNode<ResizeObserver> m_list_node;
|
||||
|
||||
public:
|
||||
using ResizeObserversList = IntrusiveList<&ResizeObserver::m_list_node>;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user