mirror of
https://github.com/captbaritone/webamp.git
synced 2026-01-23 02:15:01 +00:00
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:
parent
89946763b6
commit
37b4e9c387
1 changed files with 3 additions and 11 deletions
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue