0

Android surfaceView still consumes memory after finishing the activity and killing the thread. Memory usage increases every time I restart my game (closing and opening). Cant figure it out :( Surface Destroyed method:

@Override
    public void surfaceDestroyed(SurfaceHolder holder){

                holder.lockCanvas();
                thread.setRunning(false);
                thread.join();
                retry = false;
                thread=null;


        }

    }

Surface created:

@Override
    public void surfaceCreated(SurfaceHolder holder)
    {
        thread = new MainThread(getHolder(), this);
        thread.setRunning(true);
        if(thread.getState() == Thread.State.NEW)
        thread.start();

}

This method finishes the activity:

private  void restart()
    {
        thread = new MainThread(getHolder(), this);
        thread.setRunning(false);
        thread=null;
            ((Activity) getContext()).finish();
    }
limus
  • 1
  • 1

1 Answers1

0

I solved the problem by setting lauchMode to singleTask. Thanks to this: Memory and Activities :: OutOfMemory

Community
  • 1
  • 1
limus
  • 1
  • 1