javascript - FileReader memory leak -
i'm using filereader upload image files client data fetching , thumbnails display.
what i've noticed is, on page process, in task manager, memory keeps going higher , higher. , when process stops, , memory stay high , never goes down.
can please tell me doing wrong here?
to check, please upload more 200 pictures, 30mg. , see memory keeps on leaking
thank in advanced.
-- here link code example on web
and here code:
<input class="fu" type="file" multiple="multiple" /> <div class="fin"></div> <div class="list"></div> <script type="text/javascript"> $(document).ready(function () { var input = $("body input.fu"); input[0].addeventlistener('change', fu.select, false); }); var fu = { list: [], index: 0, select: function (evt) { evt.stoppropagation(); evt.preventdefault(); var files = evt.target.files ? evt.target.files : evt.datatransfer ? evt.datatransfer.files : []; // filelist object fu.list = files; fu.index = 0; fu.load(); }, load: function () { var index = fu.index; var file = fu.list[index]; if (file) { var reader = new filereader(); // file api object reader.onloadend = (function (thefile) { return function (evt) { if (evt.target.readystate == filereader.done) { settimeout(fu.load, 20); } }; })(file); reader.onprogress = null; reader.onloadstart = null; reader.onerror = null; reader.onabort = null; if (reader.readasbinarystring) { reader.readasbinarystring(file); } else { reader.readasdataurl(file); } fu.index++; $('.fin').html("#" + fu.index); } else { $('.fin').html("finish"); } } } </script>
ok, have fixed this.
the reason set reader - new filereader() - each time.
so made global.
here working code:
<script type="text/javascript"> $(document).ready(function () { var input = $("body input.fu"); input[0].addeventlistener('change', fu.select, false); }); var fu = { list: [], index: 0, reader: null, select: function (evt) { evt.stoppropagation(); evt.preventdefault(); var files = evt.target.files ? evt.target.files : evt.datatransfer ? evt.datatransfer.files : []; // filelist object fu.list = files; fu.index = 0; fu.reader = new filereader(); // <- made once fu.load(); }, load: function () { var index = fu.index; var file = fu.list[index]; if (file) { fu.reader.onloadend = (function (thefile) { return function (evt) { if (evt.target.readystate == filereader.done) { fu.reader.abort(); settimeout(fu.load, 5); } }; })(file); fu.reader.onprogress = null; fu.reader.onloadstart = null; fu.reader.onerror = null; fu.reader.onabort = null; if (fu.reader.readasbinarystring) { fu.reader.readasbinarystring(file); } else { fu.reader.readasdataurl(file); } fu.index++; $('.fin').html("#" + fu.index); } else { $('.fin').html("finish"); } } } </script>
Comments
Post a Comment