Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Modern Media Controls] HTMLMediaElement is never destoyed when showi…
…ng media controls https://bugs.webkit.org/show_bug.cgi?id=270571 Reviewed by NOBODY (OOPS!). At least in GStreamer-based ports (WPE and WebKitGTK, I haven't checked on Mac ports because I don't have the proper environment easily available), the media element is leaked after explicit deinitialization and detaching from the HTML document, even after manually triggering garbage collection (GC) using the web inspector. See: WebPlatformForEmbedded/WPEWebKit#1285 After some debugging, we've detected that 2 extra references to HTMLMediaElement appear when using the controls (3 refs in total), while in a scenario where the controls are hidden on purpose only 1 reference remains, which is released as soon as the GC kicks in. Those references are held (or transitively held) by the MediaController, the shadowRoot referenced by the MediaController and by the IconService, and the <div> element that MediaController adds to the shadowRoot as a container for the controls. This commit adds code to deinitialize the MediaController when HTMLMediaElement is no longer in use. The best place mathing that instant is pauseAfterDetachedTask(). This deinitialization takes care of properly nulling the mentioned objects that hold (or transitively hold) the references to HTMLMediaElement. A new MediaController.deinitialize() method has been added to the JavaScript code for this purpose. * Source/WebCore/Modules/modern-media-controls/media/media-controller.js: (MediaController.prototype.deinitialize): Set references to the media element and the shadow root to null and also detach the UI container from the shadow root, so no references to HTMLMediaElement are held anymore, either directly or transitively. * Source/WebCore/html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::pauseAfterDetachedTask): Add code to call to the MediaController.deinitialize() JavaScript method.
- Loading branch information