From 88d2a0227bc23ae2e02d45fd3fc27cd3d3e3f66d Mon Sep 17 00:00:00 2001 From: theodab Date: Mon, 24 Jun 2024 03:14:33 -0700 Subject: [PATCH] fix(preload): Fix memory leak with preload feature (#6894) There was a memory leak where the segments that the PreloadManager prefetched did not get cleaned up, after the player unloads. This fixes that memory leak. Fixes #6883 --- lib/media/streaming_engine.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/media/streaming_engine.js b/lib/media/streaming_engine.js index 87167d02b1..7d5ab935eb 100644 --- a/lib/media/streaming_engine.js +++ b/lib/media/streaming_engine.js @@ -157,6 +157,10 @@ shaka.media.StreamingEngine = class { for (const state of this.mediaStates_.values()) { this.cancelUpdate_(state); aborts.push(this.abortOperations_(state)); + if (state.segmentPrefetch) { + state.segmentPrefetch.clearAll(); + state.segmentPrefetch = null; + } } for (const prefetch of this.audioPrefetchMap_.values()) { prefetch.clearAll(); @@ -244,6 +248,7 @@ shaka.media.StreamingEngine = class { if (!(config.segmentPrefetchLimit > 0)) { // ResetLimit is still needed in this case, // to abort existing prefetch operations. + state.segmentPrefetch.clearAll(); state.segmentPrefetch = null; } } else if (config.segmentPrefetchLimit > 0) {