From 37b4e9c387b849af4a6381f190967a38f435f0f8 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 29 Nov 2025 00:24:21 +0000 Subject: [PATCH] Reuse reducer cleanup logic in dispose() Instead of duplicating cleanup code, dispatch REMOVE_ALL_TRACKS action to reuse the existing cleanup logic in the tracks reducer. This follows DRY principles and ensures consistent cleanup behavior. --- packages/webamp/js/webampLazy.tsx | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/packages/webamp/js/webampLazy.tsx b/packages/webamp/js/webampLazy.tsx index d0cd7820..6d055a54 100644 --- a/packages/webamp/js/webampLazy.tsx +++ b/packages/webamp/js/webampLazy.tsx @@ -528,17 +528,9 @@ class Webamp { * attempt to clean itself up to avoid memory leaks. */ dispose(): void { - // Clean up all object URLs to prevent memory leaks - const state = this.store.getState(); - const tracks = Selectors.getTracks(state); - Object.values(tracks).forEach((track) => { - if (track.url && track.url.startsWith("blob:")) { - URL.revokeObjectURL(track.url); - } - if (track.albumArtUrl && track.albumArtUrl.startsWith("blob:")) { - URL.revokeObjectURL(track.albumArtUrl); - } - }); + // Clean up all object URLs by dispatching REMOVE_ALL_TRACKS + // This reuses the cleanup logic in the tracks reducer + this.store.dispatch({ type: "REMOVE_ALL_TRACKS" }); this.media.dispose(); this._actionEmitter.dispose();