Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6356705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:01:10+00:00 2026-05-24T23:01:10+00:00

FileReader seems to consume all the memory as it is repeatedly used to preload

  • 0

FileReader seems to consume all the memory as it is repeatedly used to preload multiple blobs, and never frees it. Any known way to force it to release consumed memory? Setting FileReader object and it’s result property to null doesn’t seem to work.

UPDATE:

Here is a sample code (test it on a big files, like movie, or you won’t notice the effect in task manager):

<input id="file" type="file" onchange="sliceMe()" />

<script>
function sliceMe() {
    var file = document.getElementById('file').files[0], 
        fr,
        chunkSize = 2097152, 
        chunks = Math.ceil(file.size / chunkSize), 
        chunk = 0;

    function loadNext() {
       var start, end,
           blobSlice = File.prototype.mozSlice || File.prototype.webkitSlice;

       start = chunk * chunkSize;
       end = start + chunkSize >= file.size ? file.size : start + chunkSize;

       fr = new FileReader;
       fr.onload = function() {      
          if (++chunk < chunks) {
             // shortcut - in production upload happens and then loadNext() is called
             loadNext(); 
          }
       };
       fr.readAsBinaryString(blobSlice.call(file, start, end));
    }

    loadNext();
}
</script>

I tried to create fresh FileReader instance every time, but the problem still stays. I suspect that it could be caused by a circular nature of the pattern, but I’m not sure what other pattern can be used in this case.

I checked this code in both Firefox and Chrome and Chrome seems to handle it more gracefully – it purges memory after each cycle and is very fast. But the irony of the situation is that Chrome doesn’t need to use this code at all. It’s just an experiment to overcome Gecko 6- FormData + Blob bug (Bug 649150 – Blobs do not have a filename if sent via FormData).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T23:01:13+00:00Added an answer on May 24, 2026 at 11:01 pm

    Bug has been marked as INVALID, since it turned out that I wasn’t in fact re-using FileReader object properly.

    Here is a pattern, which doesn’t hog memory and cpu:

    function sliceMe() {
        var file = document.getElementById('file').files[0],
            fr = new FileReader,
            chunkSize = 2097152,
            chunks = Math.ceil(file.size / chunkSize),
            chunk = 0;
    
        function loadNext() {
           var start, end,
               blobSlice = File.prototype.mozSlice || File.prototype.webkitSlice;
    
           start = chunk * chunkSize;
           end = start + chunkSize >= file.size ? file.size : start + chunkSize;
    
           fr.onload = function() {      
              if (++chunk < chunks) {
                 //console.info(chunk);
                 loadNext(); // shortcut here
              }
           };
           fr.readAsBinaryString(blobSlice.call(file, start, end));
        }
    
        loadNext();
    }
    

    Another bug report has been filed: https://bugzilla.mozilla.org/show_bug.cgi?id=681479, which is related, but not the evil in this case.

    Thanks to Kyle Huey for bringing this to my attention 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Java process that opens a file using a FileReader. How can
I've been using the idiom below for some time now. And it seems to
In my place where I work, used to have files with more than million
I'm doing what seems like a simple read from a data file, and it's
I am using HTML 5 FileReader to read more that one file asynchronously. I
Using Java is there an easy way to check whether a given file conforms
My code needs to read in all of a file. Currently I'm using the
Can someone give me an example of using the FileReader API go get contents
I'm trying to unpack a binary string sent via Javascript's FileReader readAsBinaryString method in
I got this far, but it seems that buffer won't take arrays, because first

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.