每次我创建新线程时,它都会被添加到主ThreadGroup中,甚至我也会空线程,它仍然存在于主ThreadGroup中,导致内存泄漏。请帮帮忙
更新的
public void surfaceDestroyed(SurfaceHolder holder) {
Log.d("mThread", "Surface Destroyed Called");
getHolder().removeCallback(this);
boolean retry = true;
_thread.setRunning(false);
while (retry) {
try {
Log.d("mThread", "b4 Interrupted");
_thread.interrupt();
Log.d("mThread", "b4 thread group Interrupted");
_thread.getThreadGroup().interrupt();
Log.d("mThread", "b4 join");
_thread.join();
retry = false;
} catch (InterruptedException e) {
Log.d("mThread", "Interrupted");
Thread.currentThread().interrupt();
_thread.getThreadGroup().list();
_thread = null;//======>here nulling thread
break;
}
}
}发布于 2011-06-10 10:26:28
问题不在于它被添加到线程组中。已终止的线程将始终(最终)从线程组中删除。
如果应用程序正在泄漏内存,则代码中有一个bug。你弄错了树。
发布于 2011-06-10 10:25:19
如果线程存在于您的ThreadGroup中,并且需要删除它,则可以使用ThreadGroup类的.remove()方法。它从ThreadGroup组中移除指定的线程。
语法:
void remove(Thread t);
// t is thread to be removed from the ThreadGroup.https://stackoverflow.com/questions/6304985
复制相似问题