w3c / w3c/csswg-drafts

[resize-observer] Suggest using weak references

Open
#6,397 6 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

resize-observer-1
Dominant language
Bikeshed
Stars
4.9k
Forks
816
PR merge metrics
PR metrics pending

Description

https://drafts.csswg.org/resize-observer/

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, ResizeObserver leaks memory. The same happens with IntersectionObserver.

https://bugs.chromium.org/p/chromium/issues/detail?id=1220041 (includes demos) - the same issue effects Firefox and Safari.

The ResizeObserver spec should suggest that observed elements are weakly referenced, similar to MutationObserver.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read the linked Resize Observer draft and compare its handling of observed elements with the MutationObserver garbage-collection guidance. Review the linked IntersectionObserver issue and Chromium bug demos for the reported leak. Done means the ResizeObserver specification clearly recommends weakly referencing observed elements, if that behavior is appropriate.

Written by the indexing model from the issue text.

Assessment

Domain
documentation, web-dev
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.