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 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!