问题描述
我使用jQuery 1.4.4和使用。获得API来检查,看看是否我需要刷新页面或不上的数据。问题是,有内存泄漏的地方在下面的代码片段,我似乎无法找到。你会发现,我做的可能没用的东西很多喜欢这里删除并重新添加定时器都在努力弄明白是怎么回事。我假定做.load是造成问题,但在这一点上,.load不会发生非常频繁可言,只有当来自。获得返回true的数据,这是非常相当罕见,并且不与内存泄漏我看到使用Windows任务管理器一致。有一点需要注意的是,这个不漏全部使用Firefox时,似乎是IE浏览器特有的。我使用IE 8,但不认为这事情了。
I am using jQuery 1.4.4 and use the .get API to check to see if I need to refresh data on a page or not. The problem is that there is a memory leak somewhere in the snippet below that I cannot seem to find. You will notice that I do a lot of potentially useless things here like deleting and add back the timer all in an effort to figure out what is going on. I assumed that doing the .load was causing the problem, but at this point, the .load doesn't occur very frequently at all, only when the data from .get returns "true", which is very fairly infrequent and doesn't coincide with the memory leaking I see using windows task manager. One thing to note is that this does not leak at all using Firefox, seems to be IE specific. I am using IE 8 but don't think that matters much.
<script>
$(document).ready(function() {
function CheckAlerts() {
//Must tell Ajax not to cache results
$.ajaxSetup({ cache: false });
$.get("AjaxDataCheck/CheckForDataRefresh.cfm", { datacheck: "MyAlerts"},
function(data) {
if (data.indexOf("true") >= 0) {
$.ajaxSetup({ cache: false });
$('#responsecontainer').load('alertchecking_Inner.cfm');
//Clearing the timer and recreating may force gargage collection.
clearTimeout(CheckAlertsTimer);
delete CheckAlertsTimer;
CheckAlertsTimer = setTimeout(CheckAlerts,2000);
}
else
{
//Clearing the timer and recreating may force gargage collection.
clearTimeout(CheckAlertsTimer);
delete CheckAlertsTimer;
CheckAlertsTimer = setTimeout(CheckAlerts,2000);
}
});
CheckAlertsTimer = setTimeout(CheckAlerts,2000);
};
CheckAlerts()
});
</script>
谢谢!
推荐答案
这是发生在load()函数存在一个问题,释放的DOM元素。这是专门针对IE浏览器,和一个解决方法是
This occurs as the load() function has an issue releasing dom elements. This is specific to IE, and a workaround is
document.getElementById("responsecontainer").innerHTML = $('#responsecontainer').load('alertchecking_Inner.cfm');
截至 http://forum.jquery.com/topic报道/内存泄漏,与阿贾克斯 - 电话的。
这篇关于内存泄漏使用jQuery。获得API和setTimeout的当的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!