So I have been working on an arcade/fast action lots of going on type android game.
Using libgdx for testing mostly on desktop, with occasional test on android
It was running mostly fine in all my tests, never had any issues.
But as my game has grown with complexity and number of entities
[b]my game would crash occasionally, and I isolated it to a out of memory type of problem.
So one of the causes I thought was my massive amounts of ‘new explosions’ being called and allocating/destroyed many times a second, so my first thought was to build an ExplosionManager, that keeps them stored there, pulls one out randomly(unordered) uses it, and then sticks it back in there, and will add more if there are none left to give. This way I could never call ‘new’ very often, and just keep a copy of it.
This solved my first problem.[/b]
But I noticed, it still happened on occasion. So I ran some trial runs, with no explosions, and such and still found some unusual behavior. I believe that 1 of 2 things might be happening. My garbage collection isn’t happening frequently enough and I need to make a Manager for everything, or something isnt going out of scope and thus being GC when it should be.
So Luckily, I recently discovered Java VisualVM (included with your SDK) and I love it.
Although I have since limited the number of created entitiy bad guys. I first played for a little while., thus the ‘growth’ in the beginning, then I let my player die, and the bad guys just spawn/shoot/d to their thing
After running it idle for 15 minutes, it seems to be pretty consistent, thus memory is being handled pretty decently on its own.
However, most of the causes seems to point back to my floats is what is sucking up the most memory.
about 18 megabytes per 1k instances of float[], isn’t a float about 4 bytes? So shouldn’t this be more like 4-5 megabytes and not 15+?
I can’t null them, and I am not sure if setting them to 0 when I am not using it, would help any.
Unless each float[] is a collection of floats, and not representing an actual float? Even though I have no defined float[] or even any collections of floats
Any suggestions on smoothing out performance spikes or helping the GC improve a little bit?
Especially with floats or entitymanagement? (I originally and for the longest time, thought it was an issue with the textures/graphics) but it doesn’t seem to be the case?
The biggest issue is when too much stuff is happening and there isn’t enough time for GC to kick in, thus things overload the phone’s memory.
There is plenty of memory on my desktop, but still a concern.
[SOLVED]
I was calling “new ShapeRenderer()” with every new entity on the screen, even though I wasn’t using it.