i have an object which is needed through out the game in every 10 seconds.
shall i keep on deleting the object or keep on using the same object ?
where does the object lies in so called “free time”?
as it’s a mobile game, memory is a concern.
so, just wanted to know which method would be fruitful.
"creating and deleting objects" ?
or
"reusing a object" ?
thanks
This depends very much on the nature of the object and the memory use of the rest of the program, but as a rule of thumb:
If you need the object throughout the program, then keep it in memory. If it’s small, it won’t matter. If it’s big, then re-creating it every ten seconds will be a strain on the processor and the allocations might contribute to memory fragmentation as well.
If you choose to keep the object alive as I recommended, then while it’s not used it will live in RAM and take up some space there (assuming your mobile platform does not have swap memory).