Javascript - File saved on disk stuck in Chrome's memory

I have this code:

function saveFile(str, part) { var textFileAsBlob = new Blob([str], {type:"text/plain"}); var fileNameToSaveAs = "Parsed audio - part "+part; var downloadLink = document.createElement("a"); downloadLink.download = fileNameToSaveAs; downloadLink.innerHTML = "Download File"; if (window.URL != null) { // Chrome allows the link to be clicked // without actually adding it to the DOM. downloadLink.href = window.URL.createObjectURL(textFileAsBlob); } downloadLink.click(); } 

Everything works well, except for one problem with Chrome: the โ€œfootprintโ€ blob or everything that is stored in the memory of the main Chrome process. When the download window opens, the entire block (250 MB in my case!) Is copied to the main process memory. This is bad, because if I save several files, I end up filling up the memory up to 750 MB, and at that moment the chrome stops downloading files with the error โ€œNot foundโ€. Pic: http://i.stack.imgur.com/j5PUn.jpg

Am I making some stupid mistake or is it a Chrome bug? Can I clear my Chrome memory to get rid of this problem?

+3
source share
1 answer

As my comment seemed to be the answer you were looking for, I put it as the real answer


You are not releasing the blob url after clicking, which means GC cannot get rid of blob

 // after the click URL.revokeObjectURL(downloadLink.href); 
+2
source

Source: https://habr.com/ru/post/1243636/


All Articles