My app has 2 views, the one is SurfaceView, the other is GLSurfaceView. I need switch between them frequently, so i want to just load the models once and keep them in the memory in order to speed up the switching process.
The process:
entry SurfaceView -> switch to GLSurfaceView -> load models -> init world and others -> render and display world -> switch to SurfaceView -> switch to GLSurfaceView -> just use pre-loading models without reloading -> init world and others -> render and display world -> .....
But there seems a memory-leak in my test-app, my codes(some pseudo code):
//onSurfaceCreated
if(modelsPreloded)
use preloadedModels and textures;
else
loadModels() and initTextures();
initWorldAndOthers();
addAllModelsToWorld();
buildAllObjctes();
// onSurfaceChanged
mFrameBuffer = new FrameBuffer(width, height);
// onDrawFrame
animate();
mWorld.renderScene(mFrameBuffer);
mWorld.draw(mFrameBuffer);
mFrameBuffer.display();
// onTouchEvent
if(touch down)
mActivity.setContentView(new MyGLSurfaceView(mActivity));
With per touching down, the memory usage will increase about 500K. But what i expect is that there should be non memory usage increasing when switching from an old GLSurfaceView to the new one.
And if i change code to de-active "mWorld.renderScene(mFrameBuffer)" and "mWorld.draw(mFrameBuffer)", there will no memory usage increase when i touch down:
// onDrawFrame
animate();
//mWorld.renderScene(mFrameBuffer);
//mWorld.draw(mFrameBuffer);
mFrameBuffer.display();
Should i do some clear work before switching views? I tried mFrameBuffer.freeMemory() and mFrameBuffer.dispose(), seems useless.