Reputation: 31
I use TextureView
for displaying a OpenGL graphics. I have a few TextureView
screens. Also I have a lot of graphic content such as sprites or text glyphs, and I don't want to create it again when screen is swithed. I found that EGL shared context can help me.
val surfaceAttributes = intArrayOf(
EGL14.EGL_WIDTH, 1,
EGL14.EGL_HEIGHT, 1,
EGL14.EGL_NONE
)
sharedSurface = EGL14.eglCreatePbufferSurface(display, config, surfaceAttributes, 0)
val contextAttributes = intArrayOf(
EGL14.EGL_CONTEXT_CLIENT_VERSION, 2,
EGL14.EGL_NONE
)
sharedContext = EGL14.eglCreateContext(display, config, EGL14.EGL_NO_CONTEXT, contextAttributes, 0)
I use these context and surface as global objects. Whe application starts I load all necessary for me resources. For each TextureView I create a new EGLContext
with sharedContext
:
val context = EGL14.eglCreateContext(display, config, sharedContext, contextAttributes, 0)
It works fine but there is a poblem with a memory leak. I destroy EGLContext
and EGLSurface
asitiated with TextureView
in onSurfaceTextureDestroyed
method but a graphics memory doesn't free after destroying a TextureView
object (I checked it via Profiler).
I found that all memory frees only after destroyng my sharedContext
.
Is there any way free from memory leaks to preserve OpenGL resources (sprites, glyphs) during all applications life time?
Upvotes: 1
Views: 1048
Reputation: 31
I found a very dummy solution which doesn't allow to flow out of memory and to have a lot of TextureViews on different screens. I just keep my TextureView as a static object and in a fragment's onCreateView method I place my keeped TextureView in a special placeholder view.
It works because as it turned out these memory leaks related with destroying and creating of TextureView.
If you don't destroy TextureView then a memory leak won't happen.
Upvotes: 1