Android Surfaceview Threads and memory leaks

后端 未结 2 1594
青春惊慌失措
青春惊慌失措 2021-02-04 15:55

Im creating a game in android, and i noticed that the game has a memory leak. Iv managed to isolate the memory leak into a smaller application so that i can see well try and wor

相关标签:
2条回答
  • 2021-02-04 16:49

    As you can see here:

    http://developer.android.com/resources/articles/avoiding-memory-leaks.html

    The easiest way to start a memory leak in Android is to pass a view's constructor the whole activity instead of the application context. Have you try to change this line:

    setContentView(new MemoryLeak(this));
    

    into this one:

    setContentView(new MemoryLeak(Context.getApplicationContext()));
    

    ?

    Hope it helps.

    0 讨论(0)
  • 2021-02-04 16:57

    You should not create new Thread in the constructor when you are creating it in onSurfaceCreated. Compare your code to my example: How can I use the animation framework inside the canvas?

    0 讨论(0)
提交回复
热议问题