以下代码导致内存泄漏(您可以看到发生这种情况的越多,您将鼠标悬停在其中的速度越慢)。不幸的是,我无法在我的办公室下载javascript分析器(我可以,它只会花我几天/周)。导致内存泄漏的jQuery代码
下面是代码,只是一个下拉菜单一些简单的转换:
$(document).ready(function(){
breadcrumbOver = function() {
$(this).stop().animate({ backgroundColor: "#3393b5", textIndent: 15 }, 250);
}
breadcrumbOut = function() {
$(this).stop().animate({ backgroundColor: "#738793", textIndent: 0 }, 250);
}
$("nav ul li").hover(
function() {
$(this).children('ul.child').stop().slideDown('fast').children('li').hover(breadcrumbOver, breadcrumbOut);
},
function() {
$(this).children('ul.child').stop().slideUp('fast').unbind(breadcrumbOver, breadcrumbOut);
}
);
});
任何人都可以看到内存泄漏可能会出现?
编辑:生动的例子在这里 - http://rcnhca.org.uk/sandbox/(反复翻转“健康,安全和安全”,然后翻转它的孩子看到效果发生,也动画slideDown有时不滚动,如果你进出速度足够快)。
大多数时候,在路上,我们的代码会导致内存泄漏。 – 2012-04-12 15:42:05
您在浏览器开发者工具中发生了什么?如果你看,你的各种动画可能会向你展示自己。你可以从这里讲很多。 – veeTrain 2012-04-12 15:44:40
@veeTrain我只有萤火虫,除了引发这个错误外,没有任何异常显示:“WebGL:无法获得可用的WebGL上下文。”这与Modernizr不是我的剧本有关。 – 2012-04-12 15:54:41