我已经做了一点研究,并发现使用setTimeout()导致不良内存泄漏,如this post所示。我希望找到一种补救办法或替代方案。setTimeout内存泄漏在钛加速器
我所拥有的是当我的许多按钮被触摸时出现在屏幕上的小视图。同时,我设置了一个超时,以在3秒后淡出小视图。当第一次按下按钮时,我也会清除超时时间,这样我就不会继续设置多个按钮。尽管现在在分析我的代码时,我发现我正在设置一个时间间隔并清除超时。不知道这是否是我的问题的一部分。它看起来像这样:
var Modal = Titanium.UI.createView({
width:151,
height:83,
owner: null,
myView: null,
});
var modalTimer;
var addModal = function(){
clearInterval(modalTimer);
theView.add(Modal);
modalTimer = setTimeout(function() {
removeModal();
changeTurn();
},3000);
}
playerButton.addEventListener('click',function(){
addModal();
});
谢谢!
与你在你的问题中提到的你调用`setTimeout()`和`clearInterval()`相反。 – nnnnnn 2011-12-14 05:46:19
非常真实,将它们混合起来...... – gjunkie 2011-12-14 06:41:14