I am testing a game concept for mobile, on very weak cpus. While doing that i noticed a strange behavior.
Creating and destroying the same objects over a while creates some kind of overhead which eats more and more CPU!
And that goes without haveing more objects on the screen. After letting the generator run for like 4 minutes the game becomes on playable on mobile.
Does anyone have an idea what this could be? I checked everything and there is nothing filling up or anything that could cause this behavior.
In the beginning the object creation takes about 1% CPU and after a few minutes its already 6-7%
The objects get destroyed when they behind the player, there are never more than 130 objects on the screen.
The only possible cause for me would be multiplying bigger numbers for position, could that be the issue?
This is the complete object creation code (no, the array does not have more than a few entrys at any given time, as long as the cpu can keep up:
This is how it looks like: gyazo.com/0abb10141bf6ac799fbfa26df554f4fd
This is the CPU Usage on a ryzen after 10 minutes: gyazo.com/6beed8369ee3aa9d22a9397f9a7076f9
What am i doing wrong here?
Kind regards
Patrick
Quick update: I removed the distance calculation from the single objects and do it now in the beginning once for all objects. it takes like no cpu time at all even after Minutes of running. So something with the object creation / Placement must be wrong here...