Problem with jQuery + Chrome

I run this script in Google Chrome using the Chrome Task Manager to monitor memory usage:

<html>
<head>
    <title>Test Page</title>
    <script type="text/javascript" src="jquery-1.3.2.js"></script>
    <script type="text/javascript">

        var count = 0;

        function incrementContent() {
            $("#content").text(count);
            count++;
            setTimeout(incrementContent, 5);
        }

    </script>
</head>
<body onload="incrementContent()">
<div id="content">
</div>
</body>
</html>

Memory usage will constantly increase to a maximum of ~ 31,000 K, and then will remain at that level.

As far as I can see, the loop should just overwrite the same element in the document.

What causes the allocation of a large amount of memory?

Using IE 8, I do not see a noticeable increase in memory usage while the script is running.

Using Firefox 3.5.3 uses a several megabyte increase cycle for a minute or so, and then drops the baseline.

+3
source share
2 answers

Chrome jQuery? , jQuery jQuery , .

, jQuery script. CDN?  Google AJAX CDN Microsoft AJAX CDN

+2

setTimeout. . , .

, Java, StackOverflowException. , Javascript, .

setInterval:

function incrementContent() {
    $("#content").text(count);
    count++;
}
setInterval(incrementContent, 5);
+1

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


All Articles