The solution is in the last edit.
This really happened on my younger devices ( GT-S5830
and GT-S5830i
).
The fact is that this did not happen due to low memory; I registered the current memory usage in my game and it did not cross 3 megabytes when I was 80 or more megabytes of free bar. I even executed System.gc()
sequentially, which tells the garbage collector to free up space in space.
I have no workaround, but I will update this answer as soon as I find it.
After some searching, gpu-related material (e.g. textures) is not managed by the garbage collector (therefore, they should be deleted manually). Therefore, calling System.gc()
is somehow pointless. However, I delete all my textures, and the memory usage in my game is pretty low.
I tried all kinds of solutions and nothing worked, but here is something that should fix the problem (I have not tried this, but should work nonetheless):
Just don't load so many textures over and over again. My game was used to recycle and then initialize all textures whenever the user moved from the screen. Perhaps this is causing the problem. What you need to do is save the loaded textures / texture atlases in memory (do not lose their link). Thus, switching to the screen will not reload all textures.
Avoid using raw Texture
and use POT (Power Of Two) TextureAtlas
.
I will apply these two steps to my project, and if the problem goes away, I will return to confirm my decision.
It's not a problem. I spent a very long cycle of utilization and loading of textures, there were no exceptions / errors. My suggestion above is not a solution. The problem is probably related to the excessive Screen
switching, but I think not, because this problem also occurs when the screen orientation changes from portrait to landscape mode and vice versa.
Decision:
I thought that Game
setScreen(screen)
automatically calls Screen
dispose()
(which is not the case). dispose()
used to remove all my base textures. I just solved the problem by calling dispose()
in Screen
hide()
overridden method.
Using TextureAtlas
very important because you reduce the number of descriptors attached to each Texture
. (What could be causing the EGL_SUCCESS error)
Tested on both the GT-S5830
and GT-S5830i
(Samsung Galaxy Ace and Samsung Galaxy Y). The problem no longer arises.