📜 ⬆️ ⬇️

A simple, seemingly javascript question.

There is a seemingly simple code:

setInterval(function(){ var xhr = new XMLHttpRequest(); xhr.open('GET', 'json.txt', true); xhr.onreadystatechange = function() { if(this.readyState == 4 && this.status == 200) { console.log(this.responseText); } }; xhr.send(''); }, 500); 


If you leave this code working in, for example, Google Chorme, say, for 1 hour, it eats up memory. Eats methodically. If you look in the Developer Tools at the memory usage profile, you can see that the memory is still cleaned by the GC but not completely. Over time, the minimum point on the graph after GC increases.
')
image

Similarly, the growth in memory consumption is also visible in about: memory. The "fatty" memory is consistently visible in the FF ...

Important ...


In addition to this code, there is no more code on this page at all.

Maybe I do not understand how GC works in JS, but in my concept there is nothing to flow and nothing to live forever. Can someone explain why?

PS There is no “real” leak, if you refresh the page - the memory is cleared.
PPS There is a local vital need (“business requirements”) to leave a code similar in structure at much longer intervals than 1 hour.

UPD: It turns out there is even a ticket in chromium: code.google.com/p/chromium/issues/detail?id=52411
UPD: Supposedly fixed in 9, but I check for 10.

Source: https://habr.com/ru/post/117909/


All Articles