Canvas draw and animation creating Memory Leaks
See original GitHub issueWavesurfer.js version(s):
1.4.0
Browser version(s):
Safari and Chrome
Use behaviour needed to reproduce the issue:
All use cases …
I was seeing a never ending increase in memory usage when instantiating a wavesurfer instance and playing back an audio file (tried both, as MediaElement
and WebAudio
) that is NOT released after calling myWave.destroy()
to destroy the instance.
At first i suspected the memory leaks had something to do with WebAudio or even the Media element, but then to test this theory, i modified the wavesurfer code and disabled the render of the canvas.
As soon as i disabled the render of the canvas the memory leak was gone.
It seems there are references to the canvas elements, event listeners and animation that are not properly removed on destroy.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Android canvas.draw leaks graphic memory - Stack Overflow
After testing your code, instead of a memory leak, seems to be allocated memory space which hasn't been reclaimed yet.
Read more >HTML5 Canvas How to avoid Memory leaks Tip - Konva
HTML5 Canvas How to avoid Memory leaks Tip ... using konva, author is creating new layers, stages, shapes, texts and from that he...
Read more >(Fix) Memory Leaks: Animating HTML5 Canvas - Illyriad
What we are interested in is how to fix it, and also achieve some performance gains from not continuously creating DOM elements. The...
Read more >Canvas draw and animation creating Memory Leaks - - Bountysource
Coming soon: A brand new website interface for an even better experience!
Read more >Graphics - PixiJS
Create a Graphics object, set a fill color, draw a rectangle let obj = new ... be aware of the underlying GraphicsGeometry object...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
OK EVERYONE!! I can’t believe i didn’t think to try this earlier … but i believe i have made a HUGE improvement to performance and memory usage!!
VERY SIMPLY … For both the
drawBars
anddrawWave
methods, i wrapped their contents with arequestAnimationFrame()
call, and this DRAMATICALLY reduced memory usage!!!ALSO, at the end of those calls, i cancel the request and
NULL
the property.Here is what i did …
And then of course i did the same for the
drawWave
method as well.I am betting there are other improvements that can be done as it relates to memory leaks, like nulling properties when they are no longer needed, but i feel like this alone makes for a great improvement.
Hey @entonbiba, can this update be applied to the latest version?
With all that said though … i should point out that when destroying a wave instance, the memory that is used is still NOT released … VERY important to note … so this issue should remain open.
I believe though that the memory usage that is never released is likely related to the canvas elements and not necessarily the
WebAudio
orMediaElement
instance.In the meantime im working to apply the same idea to other methods like
fillRect
for exampleCheers!!
Yes, I see a lot of memory leaks on destroy in relatively young libraries, too.
Setting those values to null won’t do anything.
PR coming…