嗨,在我的应用程序中,我有一个被泄露的surfaceview类。当我使用MAT分析内存时,它会显示此类的多个实例。我想知道是否有人对如何修复它有任何见解。 下面是我认为可能导致它的一些片段。
public void surfaceDestroyed(SurfaceHolder holder) {
boolean retry = true;
thread.setPause(true);
Log.d("STATE","PAUSE2");
userPaused = true;
//sound.stopSound(1);
while (retry) {
try {
Log.d("mState","surfaceDestroy");
thread.join();
retry = false;
} catch (InterruptedException e) {
e.printStackTrace();
}
}
thread = null;
}
public void surfaceCreated(SurfaceHolder holder) {
if(thread.getState()== Thread.State.TERMINATED){
Log.d("mState","SurfaceCreatedNew");
thread = new singleThread(holder, context,true,2,true, mHandler);
thread.setPause(false);
thread.start();
}else {
Log.d("mState","SurfaceCreatedOld");
thread.setPause(false);
thread.start();
}
}
@Override
public void run() {
while (!pause) {
Canvas c = null;
try {
c = sHolder.lockCanvas(null);
synchronized (sHolder) {
if(!statePaused && !userPaused){
//Log.d("MOVE","MOVE");
powerUps();
moveAll();
}
doDraw(c);
}
} finally {
if (c != null) {
sHolder.unlockCanvasAndPost(c);
}
}
}
Log.e("mState","EndofRun");
}