The Pool class is an optimization to avoid excessive waste collection costs. The disadvantage is that you need to manually manage the objects in the pool (you must remember to release them so that they can be reused), and your objects must be reused (usually without final fields, for example).
In libGDX, the Pool class is used for objects that would otherwise be allocated for each frame (for example, Actions and Events).
You can ignore the pool for your own code until you run into problems associated with creating a lot of garbage.
How to use the pool
A Pool<> controls one type of object, therefore it is parameterized by this type. Objects are taken from a specific instance of Pool , calling obtain , and then should be returned to the pool, calling free . Objects in the pool may optionally implement the Pool.Poolable interface (which only requires the reset() method), in which case Pool will automatically reset the objects when they return to the pool. Objects are initially allocated on demand (therefore, if you never call obtain , the pool will not contain any objects).
You must implement your own subclass Pool<> because the newObject method is abstract.
Pool Prevention
Beware of leaking links to merged objects. Just because you call βfreeβ in the pool does not cancel out any outstanding links. This can lead to subtle errors if you are not careful. You can also create subtle errors if the state of your objects is not completely reset when the object is placed in the pool.
source share