So, I found that with MAT I create several Threads with each surfaceCreate
I think I need these threads, but this method calls multiple instances of ViewThread as the user is viewing my application, which is a memory leak.
How can I reorganize the way I create and process my threads so that this does not happen, or how can I stop the leak?
@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 sailed off my gameβs Career action five times, and this is what appears on MAT

EDIT: Since then, I have found that depending on the surfaceDestroyed to destroy my threads is unreliable. Now I call the corresponding thread-killing calls from another method, launched by onPause .
android memory-leaks
Houseman
source share