ventro_art
ventro_art

Reputation: 624

jQuery 3.1.1 memory leak on appendTo and empty

I found a memory leak in my code that looks like next snippet

function random() {
  return Math.floor(Math.random() * 1000);
}

var _target = $('#target');
function add() {
    _target.empty();
    for (var i = 0; i < 100; i++) {
        _target.append('<tr><td>'+random()+'</td><td>'+random()+'</td><td>'+random()+'</td></tr>')
    }
}

var addInt = setInterval(add, 500);
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Memory leak test: jquery</title>
    <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js" type="text/javascript"></script>
</head>
<body>
<table id="target"></table>

</body>
</html>

The same code that is written by innerHTML doesn't give memory leak. A tab with this code in Chrome 57.0.2987.133 (64-bit) has grown from 37 Mb to 161 Mb. The problem exists if we use any of these methods in our code :

I'm not sure about .remove() and .empty(); I couldn't find solution of this problem. All the posts that I've found are too old. Here is result of my test : enter image description here

Upvotes: 4

Views: 380

Answers (1)

mixalbl4
mixalbl4

Reputation: 3935

I've this mem leak in Chrome 57, but in 58 all is fine!

  • OS: Linux mint 17 x64
  • Chrome: 58.0.3029.81 (64-bit)

mem leak test

Upvotes: 1

Related Questions