3

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(); 
}

It works okay, except this one problem with Chrome: The blob's "footprint" or whatever is kept in Chrome's main process' memory. When download window is opened, the whole blob (250MB in my case!) is copied into main process' memory. That's kinda bad since if I save multiple files, I eventually fill memory up to 750MB, and at that point chrome stops downloading files with "Not found" error. Pic: https://i.stack.imgur.com/j5PUn.jpg

Am I doing some stupid mistake or is this Chrome's fault? Can I clean Chrome's memory to get rid of this problem?

Amareth
  • 33
  • 3

1 Answers1

2

As my comment seemed to be the answer you were looking for, I've put it as an actual answer


You're not releasing the blob URL after the click, which means the GC can't get rid of the blob

// after the click
URL.revokeObjectURL(downloadLink.href);
Community
  • 1
  • 1
Paul S.
  • 64,864
  • 9
  • 122
  • 138