I'm using this library(https://github.com/spite/ccapture.js/) to generate animated gifs from a canvas. I'm generating a significant amount of files (hundreds), which are generated as blobs and downloaded.
I'm facing a problem that, when I make a loop to generate these gifs, an enormous amout of workers are being spawned and not killed, which end up crashing the page. Here's my code:
for(i=0;i<100;i++){
let capturer = new CCapture({
framerate: 10,
format: "gif",
workersPath: "js/"
});
capturer.start();
for (let currentFrame = 0; currentFrame < totalFrames; currentFrame++) {
this.gifRender(currentFrame / totalFrames);
capturer.capture(canvas);
}
capturer.stop();
capturer.save();
}
When running this code I can see hundreds of workers being generated and piling up in my memory causing the page to crash.
I found out that this library uses this: https://github.com/jnordberg/gif.js to generate gifs. I have dived into both libraries files but couldn't find a way to fix the problem.
Reusing the same object is not possible, as there is no 'reset' method to clear it.
Have been debugging this for 10 hours now. Can anyone help?