Skip to content Skip to sidebar Skip to footer

Why Does This Function Take Up A Lot Of Memory Overtime

I'm trying to understand why does this small function after a reaches around almost 200,000 under about:memory tab it says that the devtools's total memory is: 1079408k? can someon

Solution 1:

There was speculation in comments but nobody checked, so I did it :

When you remove the console.count(), the memory stops growing. What you saw was just the console growing : those lines must be stored somewhere.

Solution 2:

The function itself continues on infinitely in a loop.

call = setTimeout(loop);

Just calls the function again, which calls that line again. There is no return statement, so the recursion never stops and it loops on infinitely.

As pointed out in the comments, it isn't necessarily recursive since there is no stack building up. The memory is building up because as dystroy pointed out

console.count();

causes the console to count the amount of times that function is called, and since it is being called infinitely, the memory is quickly filled with thousands of lines console.count() output.

Post a Comment for "Why Does This Function Take Up A Lot Of Memory Overtime"