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

Java 销毁与其他上下文共享数据的EGL上下文后不会清除内存,java,android,memory,google-cardboard,egl,Java,Android,Memory,Google Cardboard,Egl,我正在为android开发3d模型查看器。当我打开模型时,非VR视图(RenderView)将扩展GLSurfaceView加载。下面是我在该视图中的setEGLContextFactory()方法中使用的上下文工厂(日志调用和错误检查是常用的): 接下来,我按下“VR”按钮并查看哪个扩展了CardboardView(哪个扩展了GLSurfaceView)加载。这里是上下文工厂: public static class ContextFactory implements GLSurfaceVie

我正在为android开发3d模型查看器。当我打开模型时,非VR视图(RenderView)将扩展GLSurfaceView加载。下面是我在该视图中的setEGLContextFactory()方法中使用的上下文工厂(日志调用和错误检查是常用的):

接下来,我按下“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_上下文参数。我还在非虚拟现实视图上设置了PreserveegLContextonPause(true),以便在切换到虚拟现实模式后不会丢失上下文。
接下来,我按下“后退”按钮,我们返回非虚拟现实视图(RenderView)

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

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

内存被完全清除(不管创建了多少虚拟现实上下文)只有被删除的非虚拟现实上下文(与虚拟现实上下文共享数据)被销毁(当我关闭非虚拟现实视图并进入模型拾取屏幕时)

所以问题是,如果上下文是基于另一个上下文的,并且只有在“基本”上下文被销毁后才会清除,那么为什么销毁后上下文内存不会被清除?有没有办法通过GL方法解决这个问题

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);
    }
}