title: Android SurfaceView Ram Usage
body: <p>i have a very simple app.</p>
  
  <p>:: Activity ::</p>
  
  <pre><code>@Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
  
      this.setContentView(new GameView(this));
  }
  </code></pre>
  
  <p>:: GameView ::</p>
  
  <pre><code>public class GameView extends SurfaceView implements Runnable {
  
  final private SurfaceHolder holder;
  
  private boolean gameRunning;
  
  public GameView(Context context) {
      super(context);
      holder = this.getHolder();
  
      gameRunning = true;
  
      ExecutorService executorService = Executors.newSingleThreadExecutor();
      executorService.execute(this);
      executorService.shutdown();
  }
  
  @Override
  public void run() {
      Thread.currentThread().setName("GameRenderThread");
  
      while(gameRunning) {
          if(!holder.getSurface().isValid()) {
              continue;
          }
  
          Canvas canvas = holder.lockCanvas(null);
          canvas.drawColor(Color.WHITE);
          holder.unlockCanvasAndPost(canvas);
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>My problem is that the app constantly consume more and more RAM.
  The APP starts with 14.80 MB and consumed after 10 minutes already 14.94 MB.</p>
  
  <p><a href="https://i.stack.imgur.com/r7Uq0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/r7Uq0.png" alt="RAM Usage"></a></p>