So I've found, with the MAT
that I keep creating multiple Threads
with every surfaceCreate
I think I need these threads, though, but this method causes multiple instances of ViewThread
, as a user navigates through my app, which is a memory leak.
How can I reorganize the way my threads are created and handled so that this doesn't happen, or how can I stop the leak from occurring?
@Override
public void surfaceCreated(SurfaceHolder holder) {
loading=false;
if (!mThread.isAlive()){
mThread = new ViewThread(this);
mThread.setMenuRunning(true);
mThread.start();
}
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
if (mThread.isAlive()){
mThread.setMenuRunning(false);
}
}
I opened and navigated away from the Career
Activity of my game five times, and this is what shows up on the MAT
EDIT: I've since found that depending on surfaceDestroyed
for the destruction of my threads is unreliable. I now call the appropriate thread-destroying calls from a different method, triggered onPause
.