I'm new to Android development, and have been porting my game engine over to Java using libgdx over the last several weeks.
Tonight I mocked up a basic dual-stick shooter and got it to run on the Ouya, but after shooting for 2 or 3 seconds, the game starts to run very slowly- which it doesn't do on my libgdx desktop project.
I can see in logcat all the GC_CONCURRENT messages, like "GC_CONCURRENT freed 1277k, 12% free 11309K/12743K, paused 1ms+2ms, total 20ms". These messages come in extremely fast, indicating that I'm continuously bumping against some GC threshold.
I'll admit, I throw a lot of objects away, and my engine isn't optimized at all, but why is the heap size so small? I should be able to get away with the code I have if I can get more than a measly 12 MB, and the GC were invoked less often.
Even just sitting there without shooting, without generating tons of garbage objects, I'm still getting GC messages informing me I only have roughly 12% free. The android:largeHeap="true" tag doesn't seem to affect it.
Any advice?
--EDIT-- I attempted to grow the heap manually by creating a massive ArrayList of Integers at the start of my program, and then allowing it to go out of scope. This *works* to increase the heap size, which I now got to about 94 MB, but after shooting a lot (i.e. generating lots of garbage objects every frame), it still tries to garbage collect at the same rate, keeping the memory used at around 11 MB... and my framerate low with it.
Do I just need to optimize a lot? Or is there some way to get the GC to behave a bit more sanely?
Comments
b) Make sure your are using "long" and not "Long", "int" and not "Integer" for basic types.