Skip to content

Commit 8994676

Browse files
committed
Clean up object URLs in dispose() method
When a Webamp instance is disposed, clean up all object URLs from tracks and album art to prevent memory leaks. This ensures proper cleanup when the instance is destroyed, complementing the per-track cleanup that happens during normal operation.
1 parent 8ab0738 commit 8994676

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

packages/webamp/js/webampLazy.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,18 @@ class Webamp {
528528
* attempt to clean itself up to avoid memory leaks.
529529
*/
530530
dispose(): void {
531+
// Clean up all object URLs to prevent memory leaks
532+
const state = this.store.getState();
533+
const tracks = Selectors.getTracks(state);
534+
Object.values(tracks).forEach((track) => {
535+
if (track.url && track.url.startsWith("blob:")) {
536+
URL.revokeObjectURL(track.url);
537+
}
538+
if (track.albumArtUrl && track.albumArtUrl.startsWith("blob:")) {
539+
URL.revokeObjectURL(track.albumArtUrl);
540+
}
541+
});
542+
531543
this.media.dispose();
532544
this._actionEmitter.dispose();
533545
this._disposable.dispose();

0 commit comments

Comments
 (0)