Skip to content

[resize-observer] Notification after element is no longer referenced #5155

@jods4

Description

@jods4

As far as I can tell, when the ResizeObserver repo was archived, issues were closed but not copied over 😞

This is a copy of WICG/resize-observer#55 from @atotic

It is an important issue because depending on the answer, not calling disconnect or unobserve could lead to memory leaks.

Original issue:


We need to clarify Object Lifetimes for ResizeObserver and Elements.

Current specification discusses states that:

A ResizeObserver will remain alive until both of these conditions are met:

  • there are no scripting references to the observer.
  • the observer is not observing any targets.

The relationship whether RO has influence on Element object lifetime is not discussed.

Clarifying this is important in following corner case:

let el = document.querySelector("#id");
let ro = new ResizeObserver();
ro.observe(el);
setTimeout( _ => { 
  el.remove(); 
  el = null;
  // will there be any notifications after this timeout executes.
  // only remaining reference to el is inside RO.
}

Current Chrome code implicitly unobserves element if there are no JS references to it. This is not captured by the specification.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions