在销毁与其他上下文共享数据的EGL上下文后,内存不会被清除

时间:2016-03-31 07:12:11

标签: java android memory google-cardboard egl

我正在为3D模型查看器工作。当我打开模型时,扩展GLSurfaceView的非VR视图(RenderView)加载。这是我在此视图中的setEGLContextFactory()方法中使用的上下文工厂(记录日志调用和错误检查):

public static class ContextFactory implements GLSurfaceView.EGLContextFactory {
    private static int EGL_CONTEXT_CLIENT_VERSION = 0x3098;

    public EGLContext createContext(EGL10 egl, EGLDisplay display, EGLConfig eglConfig) {
        int[] attrib_list = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE };
        EGLContext context = egl.eglCreateContext(display, eglConfig, EGL10.EGL_NO_CONTEXT,
                attrib_list);

        //Reference is need to use this context as share_context parameter.
        RenderView.context = context;
        return context;
    }

    public void destroyContext(EGL10 egl, EGLDisplay display, EGLContext context) {
        egl.eglDestroyContext(display, context);
    }
}

接下来我按“VR'按钮和视图扩展CardboardView(扩展GLSurfaceView)加载。这是它的上下文工厂:

public static class ContextFactory implements GLSurfaceView.EGLContextFactory {
    private static int EGL_CONTEXT_CLIENT_VERSION = 0x3098;

    public EGLContext createContext(EGL10 egl, EGLDisplay display, EGLConfig eglConfig) {
        int[] attrib_list = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE };  
        EGLContext newContext = egl.eglCreateContext(display, eglConfig, RenderView.context, attrib_list);
        return newContext;
    }

    public void destroyContext(EGL10 egl, EGLDisplay display, EGLContext context) {
        egl.eglDestroyContext(display, context);
    }
}

如您所见,它在eglCreateContext()方法中使用RenderView上下文作为share_context参数。我还在非VR视图上设置了预测E​​GLContextOnPause(true),因此在切换到VR模式后上下文不会丢失。
接下来我按下'返回"按钮,我们返回非VR视图(RenderView)。

所有EGLCOntextFactory方法都可以正常工作,并在需要时调用。当我切换回非VR模式时,VR上下文被正确销毁,但消耗的内存未被清除

现在我再次进入VR模式,并创建另一个消耗内存的上下文。我回到非VR模式,VR上下文被破坏,但内存不再被清除。因此,每次切换到VR模式时,都会消耗越来越多的内存(每个交换机大约17 MB)。

完全清除内存(创建VR上下文的数量并不重要)仅销售非VR上下文(与VR上下文共享数据)(当我关闭非VR视图并进入模型选择屏幕时)。

所以问题是为什么在破坏后上下文存储器没有被清除,如果上下文是基于'在另一个背景下,只有在“基础”之后才会清除。上下文被破坏了?有没有办法通过GL方法解决这个问题

0 个答案:

没有答案
相关问题