我在使用 jQuery 1.4.2 时已经遇到了一些问题(http://stackoverflow.com/questions/8158739/ie-memory-leak-and-eval-with-jquery/8176724#8176724)
现在我已经将我的 jQuery 更新到 1.7.1 版本,并且每次迭代后我的内存都会缓慢增加。
这是我的代码:
var interval;
function setupdaterate(rate) {
//if the interval wasn't defined only
if (interval == undefined) {
interval = setInterval(updateitems, rate * 1000);
}
}
function updateitems() {
$('.updatable').each(function () {
var data = 'ViewObjectId=' + $(this).attr('objectid');
$.ajax({
async: true,
url: '/Ajax/GetUpdatedViewObjectDataHandler.ashx',
data: data,
type: 'POST',
timeout: 10000
}).done(function (data) {
//do the job
});
});
}
10 秒后,所有具有“可更新”类的项目都会更新。但由于某种原因,这段代码泄漏了一些内存。
它是使用 jquery ajax 的最佳方式吗?什么可能导致内存泄漏行为?
我怎么能找出问题出在哪里?有什么建议吗?