I have a little piece of code as such :
async function saveIntoMp4(chunks) {
const options = {
type: "video/webm"
}
let blob = new Blob(chunks, options);
chunks.length = 0 // to stop any memory leaks
const buffer = Buffer.from(await blob.arrayBuffer());
try {
fs.writeFile(
`./videos/1.mp4`,
buffer,
() => console.log("video is saved!")
);
} catch (error) {
console.log(error)
}
}
And everytime this function is called the occupied memory of mine goes up. It reached 4gb in fact. I have tracked the heap usage with node --inspect and I realized that arrayBuffer
is infact emptied out without an issue. Yet the memory that started at 75mb reached more than 100mb just by calling the function once as is shown in the picture. Is this a memory leak? How can I stop this from happening. I have tested it on Ubuntu 20 / 22 / Centos 9 and Rocky linux ( red hat variant ) all the same situation. The only place I am not facing memory issues is my windows 11. :