user1176073
user1176073

Reputation: 71

Android GLSurfaceView causes leak?

I am trying to use GLSurfaceView on Android and experiencing problems. I am using the code from this OpenGL article. It works well but when I rotate the device, I notice that the allocated memory is growing.

So I use MAT to check if I have a memory leak and found that there are multiple Activity instances there. If I use dominator tree, I found multiple GLThread objects (but only one is running). So is this an android GLSurfaceview bug or I'm misunderstanding something about GLSurfaceView?

Upvotes: 7

Views: 1361

Answers (1)

Mohamed_AbdAllah
Mohamed_AbdAllah

Reputation: 5322

This is commonly caused by referring to the Activity context instead of referring to the Application context. When referring to context, always use getApplicationContext() inside the Activity. Avoid using this (inside the Activity) class as it refers to the Activity.

Upvotes: 1

Related Questions