w3c / IntersectionObserver

Intersection Observer
https://www.w3.org/TR/intersection-observer/
Other
3.62k stars 523 forks source link

Suggest using weak references #474

Open jakearchibald opened 3 years ago

jakearchibald commented 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.

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.

jakearchibald commented 3 years ago

Other browser issues:

https://bugzilla.mozilla.org/show_bug.cgi?id=1717362 https://bugs.webkit.org/show_bug.cgi?id=227194