Open jakearchibald opened 3 years ago
Mutation observers suggest that they have a weak reference to observed elements, so if the element is otherwise garbage collected, then the observer is also collected. This seems to work in practice.
However, with similar code, IntersectionObserver leaks memory. The same happens with ResizeObserver.
IntersectionObserver
ResizeObserver
https://bugs.chromium.org/p/chromium/issues/detail?id=1220041 (includes demos) - the same issue effects Firefox and Safari.
The IntersectionObserver spec should suggest that observed elements are weakly referenced, similar to MutationObserver.
MutationObserver
Other browser issues:
https://bugzilla.mozilla.org/show_bug.cgi?id=1717362 https://bugs.webkit.org/show_bug.cgi?id=227194
Mutation observers suggest that they have a weak reference to observed elements, so if the element is otherwise garbage collected, then the observer is also collected. This seems to work in practice.
However, with similar code,
IntersectionObserver
leaks memory. The same happens withResizeObserver
.https://bugs.chromium.org/p/chromium/issues/detail?id=1220041 (includes demos) - the same issue effects Firefox and Safari.
The
IntersectionObserver
spec should suggest that observed elements are weakly referenced, similar toMutationObserver
.