question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Every call to wavesurferjs keeps on increasing RAM memory, without releasing it on destroy.

See original GitHub issue

I have came across a issue with wavesurferjs it does not release memory previously held upon destroy.

With high duration audio file, if we open 10 times it will hang browser itself (then we need to either hard refresh or close browser itself to continue).

Steps to reproduce on linux:

1.open terminal type $htop 2.keep on opening audio with destroy on closing. 3.memory will keep on adding

Though i’m not a good programmer, but i have found a exact solution with canvas and audio api

Here is that solution: https://stackoverflow.com/questions/53241345/web-audio-api-memory-leak?noredirect=1&lq=1

i request @katspaugh , please implement it as soon as possible.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:38 (8 by maintainers)

github_iconTop GitHub Comments

6reactions
a2-rmillercommented, Jul 20, 2020

AudioBuffer did not decrease in size and references to the buffers was being kept around even after all instances were destroyed after testing using multiple heap snapshots in Chrome.

On my end, I resolved this (before doing anything) by straight up deleting the buffer first.

delete this.wave.backend.buffer;

After the buffer is deleted, I run my regular destroying things like this.wave.destroy(); etc.

This solves the memory leak for me, which was upwards of 400mb every instantiation of a new object (using any of the recoemmdned backends).

3reactions
marcelblumcommented, Jun 10, 2020

Hello, I’ve been noticing this same issue on my end (Win 10, latest Chrome, latest Wavesurfer). I can confirm that Wavesurfer is erroneously not releasing the audio buffer after a call to destroy(), which results in the buffer not being garbage collected and persisting in memory even after subsequent calls to load() different sound files using the same Wavesurfer instance. This is most apparent when using large audio files. I know those MDN docs recommend short sound files but in practice on a decent machine Chrome handles larger audio files beautifully and I often work with tracks >1 hour in length as decoded buffers with the Web Audio API with no issues. If you set a variable holding an audio buffer to null the memory is typically purged within seconds by the garbage collector. Therefore this is almost certainly not a Web Audio API/browser bug. Wavesurfer handles drawing large sounds beautifully too, but even after a call to destroy I can see that there are still retained references to the buffer in the Wavesurfer object, preventing garbage collection. Simple example, go to https://wavesurfer-js.org/ and open the console:

wavesurfer.destroy();
console.log(wavesurfer.backend.source.buffer);
//->AudioBuffer {length: 1045146, duration: 21.773875, sampleRate: 48000, numberOfChannels: 1}
//buffer is still assigned to a variable and can't be garbage collected!
wavesurfer.backend.destroy();
console.log(wavesurfer.backend.source.buffer);
//->AudioBuffer {length: 1045146, duration: 21.773875, sampleRate: 48000, numberOfChannels: 1}
//even now buffer is still referenced in the wavesurfer object!

However even if I try manually wavesurfer.backend.source.buffer = null the buffer is still not garbage collected so I suspect there remains some reference to it even elsewhere in the Wavesurfer code that I haven’t figured out yet, perhaps you have an idea?

And just as a demonstration here is simple vanilla Web Audio API code that loads a large audio file and then purges it when done, easily observable in Windows Task Manager:

var audioCtx = new AudioContext();
var buffer;
var request = new XMLHttpRequest();
request.open("GET", "https://soundplant.org/fruits/Christian%20Wolff%20-%20Edges%20-%20Gentle%20Fire.mp3");
request.responseType = "arraybuffer";
request.onload = function() {
    console.log("loaded");
    let undecodedAudio = request.response;
    audioCtx.decodeAudioData(undecodedAudio, (data) => {
        console.log("decoded");
        buffer = data;
    });
};
request.send();
/* Chrome loads ~300mb audio data into memory observable in Task Manager */
buffer = null;
request = null;
/* usually within a few seconds, 300mb purged from Chrome's used memory observable in Task Manager */
Read more comments on GitHub >

github_iconTop Results From Across the Web

wavesurfer.js destroy() causes Uncaught (in promise ...
Things appear to be working fine, but I get this error every time and I can't figure out what seems to be the...
Read more >
Html5 Audio Buffer Keeps Increasing Js Heap Size - ADocLib
I have came across a issue with wavesurferjs it does not release memory previously held upon destroy. With high duration audio file if...
Read more >
Untitled
#5 Xbox iphone no songs, Find income tax on 1040, #Saabkyle04 mitsubishi eclipse, Hey mom what's for dinner, Afiliacion afp obligatoria.
Read more >
Bug listing with status RESOLVED with resolution UPSTREAM ...
Kernel panic: Attempted to kill init! with Dimension 8300 and P4 with Hyper Threading enabled" status:RESOLVED resolution:UPSTREAM severity:normal ...
Read more >
HAR - River Thames Conditions
Without a trace season 1 episode 13, Dj tavi, Md 82903 universal remote control, Maarten van knippenberg, Fixed asset depreciation software small business, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found