derek5. 2013-02-22 20:17 采纳率: 100%
浏览 53

jQuery Ajax内存泄漏

I am definitely not the first person to have a jQuery memory leak issue, but I couldn't find the answer I was looking for the many questions similar to this one that I looked at.

First, the leaky bit:

$(document).ready(function ivr_grabber(){
var xhr = $.ajax({
    url: '/ivr/inprogress',
    timeout: 3000,

    success: function(data){
        $('#open-ivrs').html(data);
        data = null;
    },
    complete: function(){
        setTimeout(ivr_grabber, 3000);
    }
});
xhr = null;
});

The PHP code returns a table with some people who are being called by our PBX. I've commented out the .html(data) line, and it's made no difference. I've also removed setTimeout, and then put it back, no luck. I attempted to unset all the values that might be incurring this leak, but I cant figure out where it's coming from.

It appears to be leaking at a rate of about 5 KB per ajax call. Any thoughts?

Using jQuery 1.7.2 on chrome

I've been taking heap snapshots consistently, none of the above have affected the leakiness

  • 写回答

2条回答 默认 最新

  • weixin_33690963 2013-02-22 20:20
    关注

    I'm not 100% sure on this, but try declaring the function ivr_grabber outside the scope of the document.ready handler. Also, why set the jqXHR object to null? This accomplishes nothing to my knowledge and perhaps interferes with the async request.

    $(document).ready(ivr_grabber);
    function ivr_grabber() {}
    
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘