Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 488
user1176073 Avatar asked Jan 29 '12 05:01

user1176073


1 Answers

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.

like image 145
Mohamed_AbdAllah Avatar answered Oct 11 '22 15:10

Mohamed_AbdAllah