I have a more or less completed Java game. Enemies spawn from the top of the screen and you fight them with your units at the bottom of the screen. The game uses up a lot of CPU, and I think it’s partially because every time an enemy spawns, it has a thread with it. When it dies, the memory space that is the enemy is not removed, and neither is the thread destroyed. What I’m asking is, will deleting the enemy increase efficiency, and if it does, how? Also, do you guys have any other ways to increase efficiency?
Share
What you need is a profiler.
You need to take the guesswork out of why your program is running slow. You may end up wasting a lot of time cleaning up your thread allocation only to discover it’s was not the performance bottleneck after all.
There’s are different profilers available in Java and the one you end up using will probably depend on your programming environment. Personally, I develop using the Netbeans IDE, which comes with a good profiler that I would recommend. If you develop using the Eclipse IDE, there’s VisualVM and for more options see this question:
https://stackoverflow.com/questions/2713940/eclipse-java-profiler