-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
In some cases an object removed from an array with Array.splice
is still allocated in memory, even though it is not seen in a heap dump. This results in IE(11.0.42) and Edge(38.14393) running out of memory in Windows in our web app. Chrome(58) does not have this issue.
Array.splice is a common way to remove entries in arrays. If it leaks I believe it is a huge issue for Edge.
I've created a small example. It creates an array with a large objects, and then removes the object with splice(0,1)
. Running this for a few seconds takes both IE and Edge to a memory consumption of more than 1GB, which is never freed. An inspection shows only empty arrays.
Example at https://jsfiddle.net/aefxf0v9/
// create 80kb Object
function createLargeObject(){
var temparray = [];
for(var i=0;i<10000;i++){
temparray[i]=i;
}
return { obj:temparray };
}
function leak() {
globalarray = [];
for(var i=0;i<20000;i++) {
globalarray[i]=[];
var innerarray = globalarray[i];
var largeObj = createLargeObject();
innerarray[0] = largeObj ;
//innerarray[0] = null; // Adding this will fix the problem
innerarray.splice( 0, 1 );
}
}
Setting the array entry to null before removing it with splice fixes the problem. I have made a shim for our project, but would very much like to see a solution.