Skip to content

Commit 72467ef

Browse files
committed
Fix IE11 memory leak
1 parent ab3829a commit 72467ef

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

lib/utils.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'use strict';
1+
'use strict';
22

33
var support = require('./support');
44
var base64 = require('./base64');
@@ -36,6 +36,29 @@ exports.newBlob = function(parts, type) {
3636
exports.checkSupport("blob");
3737

3838
try {
39+
// Fixed a memory leak occurred in IE11
40+
// Note:
41+
// When a large amount of Array is generated in the Blob,
42+
// the amount of memory nearly 100 times the original data amount is consumed.
43+
// Change it to create a BLOB only once after join.
44+
if (window.MSBlobBuilder) {
45+
var concatenation = function(segments) {
46+
var sumLength = 0;
47+
for (var i = 0; i < segments.length; ++i) {
48+
sumLength += segments[i].byteLength;
49+
}
50+
var whole = new Uint8Array(sumLength);
51+
var pos = 0;
52+
for (var j = 0; j < segments.length; ++j) {
53+
whole.set(new Uint8Array(segments[j]), pos);
54+
pos += segments[j].byteLength;
55+
}
56+
return whole.buffer;
57+
};
58+
// array
59+
parts = [concatenation(parts)];
60+
}
61+
3962
// Blob constructor
4063
return new Blob(parts, {
4164
type: type

0 commit comments

Comments
 (0)