Skip to content

media elements must not be freed while they are playing #48833

Closed

Description

@jschwe

Describe the bug:
The spec requires:

Media elements must not stop playing just because all references to them have been removed; only once a media element is in a state where no further audio could ever be played by that element may the element be garbage collected.

This affects subtests in following tests:

  • infrastructure/assumptions/allowed-to-play.html
  • html/semantics/embedded-content/media-elements/ready-states/autoplay.html

Running those tests with zealous GC (or manually inserting GC) reveals failures / time-outs.

We would need to ensure that media elements stay alive while they are playing (or loading?).
Gecko apparently adds a self-reference: https://searchfox.org/firefox-main/rev/9046137a91a4614ad5be3448370a8265de01affc/dom/media/mediaelement/HTMLMediaElement.cpp#7583-7617

To Reproduce:
Steps to reproduce the behavior.

Platform:
Specify OS, distribution, and hardware platform.

Activity

  1. jdm commented on Oct 16, 2026

    @jdm
    Member

    The main idea here is to add a field to HTMLMediaElement of DomRefCell<Option<Trusted<HTMLMediaElement>>>, which will create a GC cycle and ensure that the element can't be GCed. The trickier bit is figuring when we need to set that field to non-null and when we need to set it to null in order to avoid leaking media elements forever. This matters both for when playback is paused/stopped, but also if the document is unloaded.

  2. sabbCodes commented on Oct 16, 2026

    @sabbCodes
    Contributor

    I'd like to attempt this.

  3. sabbCodes commented on Oct 16, 2026

    @sabbCodes
    Contributor

    So after few hours of research, I found out that /components/script/dom/abort/abortsignal.rs has similar fix, trying to implement it.

  4. added a commit that references this issue on Oct 28, 2026
    37a706f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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