Android GLSurfaceView 导致泄漏?

发布于 2024-12-29 13:55:44 字数 443 浏览 5 评论 0原文

我尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏夜暖风 2025-01-05 13:55:44

这通常是由于引用 Activity 上下文而不是引用 Application 上下文引起的。引用 context 时,请始终在 Activity 内使用 getApplicationContext()。避免使用 this(在 Activity 内部)类,因为它引用 Activity

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文