Android OpenGL ES game not free memory when out and in of Activity GameSurface
I have a normal Main activity that calls the Game Activity Surface (in Open GL), which loads all the textures so play the game.
If I drop the activity with OpenGl surface, the engine delete the textures and close the activity game. Seems ok, but...
In Main Activity (normal activity), if I call the game activity (repeating load textures) the game dra开发者_如何学Cin much memory in heap (seems duplicate) and the frame-rate of the game get slow. If I repeat the process, the memory heap is increasing.
And what happens if I close the entire app? The Android free-up and I could re-open the app in normal speed and memory consume.
I tried garbage ... seems something related to opengl surface.
My question: closing the surface activity that contains Open gl, the open gl buffer still allocated in heap? After closed, open a new activity with open gl will duplicate the open gl size ? In memory seems that its happens, but I could finding out the reason.
I got the solution.
Because a weak reference, Android guarded all context in memory.
My game has a pause in game mainThread and show a Toast Message. The user can left or re-enter in the game. If he left the screen, Android keeps the reference of dead activity in memory, probable with all open gl surface too, only because the Toast message, with dead activity reference still popup after close the last activity. I'm just use getApplicationContext().
try to dispose all the texture in the onDestroy() method. that way all the texture will be destroyed when you exit/finish the activity.
@Override
protected void onDestroy() {
super.onDestroy();
for(Texture t:textures) {
t.dispose();
}
}
note : I don't really know that Android has it own texture class. I used libgdx and there's a dispose method to call. maybe you should find a way to dispose all those garbage. If i recall there's a recycle() method in Bitmap class that do similiar thing.
精彩评论