Why does my browser slows down when this list
data is huge in below code :
var list = [];
/*
Creating some huge dummy data
Interstingly, when I change the value of i from 10000
to 100000, the browser hangs(becomes unresponsive)
*/
for(i=0;i<10000;i++){
list.push(i);
}
/*Recursive function*/
var nextListItem = function() {
var item = list.pop();
if (item) {
console.log(item);
// process the list item...
nextListItem();
}
};
nextListItem(); // Commented this as browser becomes unresponsive.
I could not find a straight answer to my question from google, so though off getting help from SO experts. I am assuming it has something to do with browser memory as I can see the loop starts in a great speed and slowly slows down and becomes unresponsive. But not sure why?