开发者

jQuery html() memory problem

when doing the following i can watch the memory usage just soar in the task manager in chrome. i don't get it. if i comment out one line ($("#main_table tbody").html(string);) then all is fine in the world. any thoughts? thanks everyone. oh this is run once per second in a "setTimeout" loop thats how i am seeing the memory climb higher as its doing it once per second.

  $.ajax({
    type: "GET",
    dataType: 'json',
    url: '<?php echo base_url();?>includes/updateTable.php',
    cache: false,
    data: dataSt开发者_如何学编程ring,
    success: function(data)
    {
      var string = '';

      $.each(data.monitorData, function(i,monitor)
      {
        string = string + '<tr id="r'+monitor['id']+'">';

        for (var key in monitor)
        {
          string = string + '<td>'+monitor[key]+'</td>';
        }
        string = string + '</tr>';
      });

      $("#main_table tbody").html(string);
    }
  });


have you tried adding

$("#main_table tbody").empty();

right before

$("#main_table tbody").html(string);

It technically shouldn't make a difference but....


It's possible that since the string var is used in the lambda function (in $.each), javascript is not garbage collecting it.

Try adding:

delete string

to the end of the success function.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜