Bug 262485 - Safari: audio elements with event listeners are not getting garbage collected
Summary: Safari: audio elements with event listeners are not getting garbage collected
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Media (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Jer Noble
URL:
Keywords: InRadar
: 262345 (view as bug list)
Depends on:
Blocks:
 
Reported: 2023-10-02 08:06 PDT by Kin Blas
Modified: 2023-10-23 09:04 PDT (History)
4 users (show)

See Also:


Attachments
All-in-One test case that demonstrates audio element retainers (14.02 KB, text/html)
2023-10-02 08:08 PDT, Kin Blas
no flags Details
Video demonstrating how to reproduce the audio retainer with the provided test case (48.86 MB, video/quicktime)
2023-10-02 08:10 PDT, Kin Blas
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Kin Blas 2023-10-02 08:06:39 PDT
Note this bug is reproducible within Safari Desktop and Latest Webkit Builds, as well as Safari iOS 16.x

In our web application we’ve noticed a significant number of detached DOM subtrees not getting garbage collected when running in Safari Desktop and on iOS. We’ve managed to narrow the issue down to subtrees containing audio elements that have event listeners registered directly on them at the time the subtree is removed from the DOM.


The retained (leaking) subtrees in question correspond to panel UI within our application, so you can imagine how the process size of the web application tab grows steadily as the user triggers the showing and hiding of various panels. Our panels are quite large and complex so things sometimes get the point where Safari iOS will reload our web application.


Attached to this bug is an HTML file containing a minimal test case that illustrates the issue. What we’ve observed is that Safari will hold a reference to an audio element if has a src attribute defined and one or more event listeners registered on that audio element.


There is also a video attached to this bug that demonstrates what we see.


I can reproduce this issue in Safari 16.5 as well as WebKit 268505@main.


Instructions:


* Load the test case in a Safari or Webkit build.
* Click the “Remove All” button at the top of the page.
* Trigger a garbage collection via the terminal with ‘notifyutil -p org.WebKit.lowMemory’
* Observe that all of the test cases turn green except for the samples that have event listeners on them
* Click on the “Unparent All” button
* Trigger a garbage collection
* Observe that for the test cases that are not green, all elements in the sample subtrees turn red, indicating they have been garbage-collected, except for the audio elements which remain in memory.
Comment 1 Kin Blas 2023-10-02 08:08:33 PDT
Created attachment 468025 [details]
All-in-One test case that demonstrates audio element retainers

Attaching an All-in-One test case that demonstrates audio element retainers
Comment 2 Kin Blas 2023-10-02 08:10:08 PDT
Created attachment 468026 [details]
Video demonstrating how to reproduce the audio retainer with the provided test case

Attaching a video demonstrating how to reproduce the audio retainer with the provided test case
Comment 3 Radar WebKit Bug Importer 2023-10-02 08:43:15 PDT
<rdar://problem/116347723>
Comment 4 Alexey Proskuryakov 2023-10-03 16:24:01 PDT
rdar://116346717
Comment 5 Jer Noble 2023-10-05 08:20:16 PDT
Pull request: https://github.com/WebKit/WebKit/pull/18695
Comment 6 EWS 2023-10-10 13:32:44 PDT
Committed 269165@main (a2ddc404d28d): <https://commits.webkit.org/269165@main>

Reviewed commits have been landed. Closing PR #18695 and removing active labels.
Comment 7 Alexey Proskuryakov 2023-10-23 09:04:43 PDT
*** Bug 262345 has been marked as a duplicate of this bug. ***