Fix ram leak caused by not destroying Wavesurfers on reload.

This commit is contained in:
Matthew Stratford 2020-05-22 01:10:53 +01:00
parent d2db42fab7
commit d72032f3fd
2 changed files with 17 additions and 1 deletions

View file

@ -149,6 +149,11 @@ class Player extends ((PlayerEmitter as unknown) as { new (): EventEmitter }) {
return instance;
}
cleanup() {
// Let wavesurfer remove the old media, otherwise ram leak!
this.wavesurfer.destroy();
}
}
export type LevelsSource = "mic-precomp" | "mic-final" | "master";
@ -270,6 +275,16 @@ export class AudioEngine extends ((EngineEmitter as unknown) as {
return player;
}
// Wavesurfer needs cleanup to remove the old audio mediaelements. Memory leak!
public destroyPlayer(number: number) {
const existingPlayer = this.players[number];
if (existingPlayer != null) {
// already a player setup. Clean it.
existingPlayer.cleanup()
}
this.players[number] = undefined;
}
async openMic(deviceId: string) {
if (this.micSource !== null && this.micMedia !== null) {
this.micMedia.getAudioTracks()[0].stop();

View file

@ -298,7 +298,8 @@ export const load = (
if (waveform == null) {
throw new Error();
}
waveform.innerHTML = ""; // clear previous (ghost) wavesurfer
audioEngine.destroyPlayer(player);// clear previous (ghost) wavesurfer and it's media elements.
//waveform.innerHTML = "";
// wavesurfer also sets the background white, remove for progress bar to work.
waveform.style.removeProperty("background");