Is a object Pool Manager needed here?

I have made a tower defense game. I did write a object pool manager to handle the creation and pooling of objects like bullets and enemies as they are spawned rapidly.

As you know, using object pooling you create a bunch of objects in memory for future use so they dont need to be dynamically created at runtime.

My question is, should I be doing this for the towers as well? Sure, they might have 50 towers built during gameplay… but they are not created rapidly like the bullets are…

One might say, well, you already have a pool manager made, might as well use it. However, I have 8 different towers to choose from. A pool manager might create 10 or more of each tower initially in memory. Seems like a waste of memory to create 80+ towers in memory.

I’m guessing it might be fine just to create a new object as needed to save memory… but looking for another opinion.

Thanks!

It’s not going to waste a lot of memory. (until you have a lot of custom data associated with each tower)
But I’m not sure you will need pooling system for towers.

Object pooling is trying to solve several things:
As you mentioned object pooling is trying to avoid using instantiation and garbage collection on a destroyed object.

So when you tower is destroyed how much garbage is created and how often is the GC collector running to cleanup?

You can always make an object pooling system that will add a new object when pooled objects have run out. In other words create only 30 towers on startup and add as needed. You would have to really get a lot of play test to adjust this value as more people play the game.

For us we have created object pooling for systems that have 10 objects or less because the instantiation and destroy is costly for us.

Best case for you would probably be to start with the profiler and watch the gc allocations and collection when you start to hit max towers created and being destroyed.

How frequently are towers created/destroyed? You may be over optimizing.

You could also consider just not warming up the pool at all. The first few towers of each type would be instantiated in real time, but after some are destroyed you’d get the benefit of the pool, and never allocate more memory than needed for the pool. But how much memory does each tower use really? They probably are just pointing to the same assets and its just some variables for each instance which end up adding to memory, which is probably negligible memory usage.

You should really be doing performance and memory usage testing before diving into this.