关闭后,Android SurfaceView会消耗内存

时间:2015-09-12 22:32:34

标签: android memory surfaceview

Android SurfaceView在完成活动并终止线程后仍会消耗内存。每次重新开始游戏(关闭和打开)时内存使用量都会增加。无法弄明白:( 表面破坏方法:

@Override
    public void surfaceDestroyed(SurfaceHolder holder){

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


        }

    }

表面创建:

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

}

此方法完成活动:

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

1 个答案:

答案 0 :(得分:0)

我通过将lauchMode设置为singleTask解决了这个问题。多亏了这个:Memory and Activities :: OutOfMemory