I’ve got a mobile game that I’m building a pool of all game objects to be used when the game is loaded (currently 147 different objects). The objects are all set to be persistent. Before I just built the pool at the start of the level (so less objects were created, then stored, and finally destroyed each level). I’m wondering if anyone sees any potential problems with this approach or has tried something similar.
Pooling really depends. The advantages of pooling are
- You only load once
- You avoid unpredictable garbage collection
- A little more code to set up
- Unused objects remain in memory. This can cause problems on memory limited platforms. Especially if there are large spikes in the number of pooled objects
Ultimately pooling should be used when you have a large number of identical objects being frequently instantiated and destroyed. Bullets are a classic example. Obstacles in a infinite runner and enimies in a space shooter are other good candidates.
You shouldn’t use pooling for unique objects, or objects that are never destroyed. Players in a FPS or unique boss monsters are good examples.