javascript jsonp 内存泄漏
我只是有一个定期发出 jsonp ajax 请求的函数。我的函数被 setInterval 触发的另一个函数调用。
我在我尝试过的所有浏览器(IE、Safari、FireFox)中都发现内存泄漏。我在 Safari 脚本调试器中看到的是,对 ajax 请求的每个响应都在脚本调试器窗口的下拉列表中列为脚本,就好像有某种脚本对象没有被清理一样。
我正在使用jquery 1.6.2。这是一个“长期”泄漏,运行几分钟后仍未清理干净。
任何想法是什么导致了这个?
request: function ()
{
$.ajax({
url: <myurl>
dataType: "jsonp",
jsonp: "jsoncallback",
timeout: 5000,
cache: false,
beforeSend: function (xhr)
{
},
success: function (data, status, xhr)
{
},
error: function (xhr, status, error)
{
},
complete: function (req, status)
{
}
});
}
...
setInterval(request, 100);
I'm seeing the same problem described in Memory Leak When Pulling JSON from WEB.
I simply have a function that makes a jsonp ajax request periodically. My function is called by another function triggered by a setInterval.
I see a memory leak in all broswers that I've tried, IE, Safari, FireFox. Something I see in the Safari script debugger is that each response to an ajax request is listed as a script in the drop down list in the script debugger window, as if there is some kind of script object not getting cleaned up.
I'm using jquery 1.6.2. It is a "long term" leak, not cleaned up after running for several minutes.
Any ideas what is causing this?
request: function ()
{
$.ajax({
url: <myurl>
dataType: "jsonp",
jsonp: "jsoncallback",
timeout: 5000,
cache: false,
beforeSend: function (xhr)
{
},
success: function (data, status, xhr)
{
},
error: function (xhr, status, error)
{
},
complete: function (req, status)
{
}
});
}
...
setInterval(request, 100);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
事实上您每 100 毫秒发送一次 ajax 请求就足够了。
请注意,setInterval(request, 100); - 100 不是秒,而是毫秒。 1 秒 = 1000 毫秒
The fact you're sending ajax request every 100 milliseconds is enough.
Be aware, setInterval(request, 100); - 100 does not mean seconds, but milliseconds. 1 second = 1000 miliseconds
至于 jQuery 泄漏,请参阅 带有 DOM 删除的 jQuery 内存泄漏
有用于查找内存泄漏的实用程序: http://www.outofhanwell.com/ieleak/Drip-0.5.exe
@genesis 也是正确的。
As far as a jQuery leaks, see jQuery memory leak with DOM removal
There is a utility for finding memory leaks: http://www.outofhanwell.com/ieleak/Drip-0.5.exe
@genesis is correct too.