Android GLSurfaceView 导致泄漏?
我尝试在 Android 上使用 GLSurfaceView
并遇到问题。 我正在使用这篇 OpenGL 文章中的代码。 它运行良好,但当我旋转设备时,我注意到分配的内存正在增长。
于是我用 MAT 检查是否存在内存泄漏,发现有多个 Activity那里有
实例。如果我使用支配树,我会发现多个 GLThread 对象(但只有一个正在运行)。 这是 Android GLSurfaceview
错误还是我误解了 GLSurfaceView
的某些内容?
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
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这通常是由于引用
Activity
上下文而不是引用Application
上下文引起的。引用context
时,请始终在Activity
内使用getApplicationContext()
。避免使用this
(在Activity
内部)类,因为它引用Activity
。This is commonly caused by referring to the
Activity
context instead of referring to theApplication
context. When referring tocontext
, always usegetApplicationContext()
inside theActivity
. Avoid usingthis
(inside theActivity
) class as it refers to theActivity
.