public class CustomView extends View{
public CustomView (Context context) {
super(context);
}
public CustomView (Context context, AttributeSet attrs) {
super(context, attrs);
new Thread(){
@Override
public void run() {
while(true){
//dosomething;
}
}
}.start();
}
}
当屏幕配置改变或其他事情时,它会是泄漏内存吗? 如果是的话,我该怎么办?感谢。
答案 0 :(得分:1)
当屏幕配置发生变化或其他事情时,它会泄漏 存储器?
它会,因为无限循环。
我应该怎么做
你必须强制你的线程终止运行方法。例如,您可以设置将在while中评估的boolean
,并强制执行此boolean
onDetachedFromWindow