I have a code that records camera input from client into server 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)
}
}
However buffer take up the memory and doesn't let go of it on my Ubuntu 20.04.6 LTS. Everytime I run this function it keeps occupying more and more memory. I have no instance of console.log
from the buffer or chunks or blob or any kind. I am not sure why the memory is not released and what I should do about it. I have used nodejs version 20 and 18.9 so far without any luck. Why blob.arrayBuffer doesn't release the used memory?