Skip to main content
4 of 4
Making the title as a question; grammar, capitalisation, and other minor stuff.
Vaillancourt
  • 16.4k
  • 17
  • 56
  • 61

Why should I always consider creating and using object pools instead of instantiating the new object on the fly?

I have read about this pattern several times (from a best-practices perspective):

Memory Allocation: Instead of instantiating the new object on the fly, always consider creating and using object pools. It will help to less memory fragmentation and make the garbage collector work less.

However, I don’t know what it actually means. How can I implement it?

For example, I can instantiate a GameObject using the Instantiate method of Unity?

Instantiate(prefab, new Vector3(2.0F, 0, 0), Quaternion.identity);

Is this use discouraged? What else can it mean?