Merge pull request #102 from UniversityRadioYork/markspolakovs-bloody-memory-leak

Squish a memory leak
This commit is contained in:
Marks Polakovs 2020-05-01 20:22:10 +02:00 committed by GitHub
commit a0fd02f897
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -19,6 +19,7 @@ const playerGainTweens: Array<{
tweens: Between[];
}> = [];
const loadAbortControllers: AbortController[] = [];
const lastObjectURLs: string[] = [];
type PlayerStateEnum = "playing" | "paused" | "stopped";
type PlayerRepeatEnum = "none" | "one" | "all";
@ -297,6 +298,12 @@ export const load = (
const playerInstance = await audioEngine.createPlayer(player, objectUrl);
// Clear the last one out from memory
if (typeof lastObjectURLs[player] === "string") {
URL.revokeObjectURL(lastObjectURLs[player]);
}
lastObjectURLs[player] = objectUrl;
playerInstance.on("loadComplete", (duration) => {
console.log("loadComplete");
dispatch(mixerState.actions.itemLoadComplete({ player }));