YAY! Solved
Before when I had even sometimes 20 bad guys, I was hitting 15+ megs minimum, sometimes up to 70, and if I spawned 200-300 I could easily hit 300-400 megabytes pretty quickly.
I created several object pools for bullets/projectiles/particles and then some for bad guys, trying to reduce the new
It improved a lot, but it was still horrendously slow
I was reading thru all my code when I noticed something REALLY stupid
I had buried deep in my Entity base class
batch.end();
if(debug)
sr.begin() ... do shape render stuff
batch.start()
It was originally there for debugging my collision detection and realized, that even though it had long been shut off. It was still turning off/on the batch a lot, so I tried moving it into the debug statement
That improved performance a good bit, and started let me poking around more
One of the things I learned from the Java VisualVM, was that tons of floats were happening, and there were these collections of floats and stuff, from color, etc.. but it all seem 'gamestate' related, like libgdx stuff. I was confused why there was a good 50+ of them at 80kb each of tons of floats and other misc stuff that didn't seem to correlate to anything I had
Anyways, upon many stupid hours of figuring it out.
It was the silly ShapeRenderer
Even though I had encapsulated its method calls in my if(debug) boolean check
I had forgot to encapsulate the
new ShapeRenderer(); into something
It was actually being class level
ShapeRenderer sr = new ShapeRenderer();
so for Every single entity created, which there could have been 50-300 in my game. It was creating different shaperenders
I mean, I was well aware of the VERY first comment in the class "This class is not meant to be used for performance sensitive applications but more oriented towards debugging."
And I thought my debug had shielded it properly, anyways
FIXED
Even though it was a pain in the butt and broke my spirit a lot, for what ultimately was my own stupid mistakes. I did learn a lot about creating object pools(I hadn't ever made them before) I also learned a lot about Java VisualVM and examining the heap and performance.(Ive never had to do performance inspection optimizations that much in the past)
I think it was worth it, because I learned an incredible amount of useful things to apply in the future! And I won't ever make that mistake again!
tl;dr;
1. My program now runs at 4-6 megabytes even with 400 bad guys on the screen.
2. Do not forget to remove "new Shaperenderer()" when you aren't debugging(or at least encapsulate it)
and most definitely do NOT create a new instance of it with every entity created!!!
note:
(I had it over 1000 bad guys shooting, and having minor movement intelligence and didn't even break 10mb in my heap usage.) My game runs 1000x faster and smoother now. Whereas before when i hit 300 bad guys, i was at over 500 megabytes)