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.
This commit is contained in:
Claude 2025-11-29 00:24:21 +00:00
parent 89946763b6
commit 37b4e9c387
No known key found for this signature in database

View file

@ -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();