How would I implement object pooling?

I can Imagine how i would setup a pool from which to take objects, but im unsure how the objects would be returned to the pool when they are destroyed. Can I override the destroy functions? Or do I need to create my own destroy functions and disable GC on the objects.

1 Like

After the pool has been created you can request an object from the pool and then “return” it to the pool when it is no longer needed.
The pool manager obviously needs to be able to reset the object since it is being reused.

The pool manager that created the pool of objects should keep a reference to all the objects which will prevent them from ever being garbage collected.
Never destroy any of the objects but use the pool manager function to return the object for reuse instead.

3 Likes