# How to use object pooling?

**URL:** <https://forum.defold.com/t/how-to-use-object-pooling/41378>\
**Category:** Questions\
**Created:** [January 24, 2019, 2:58am UTC](https://forum.defold.com/t/how-to-use-object-pooling/41378 "2019-01-24T02:58:56Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pepsidog](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pepsidog/32/13220_2.png) [@Pepsidog](https://forum.defold.com/u/Pepsidog)\
**Post date:** [January 24, 2019, 2:58am UTC](https://forum.defold.com/t/how-to-use-object-pooling/41378/1 "2019-01-24T02:58:57Z")

</div>

In other game engines, object pooling is creating lots of objects at the start of a scene, then reusing them instead of destroying them. How can you do that with Defold?

---

<div class="post-metadata">

**Author:** ![Pkeod](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pkeod/32/606_2.png) [@Pkeod](https://forum.defold.com/u/Pkeod)\
**Post date:** [January 24, 2019, 4:22am UTC](https://forum.defold.com/t/how-to-use-object-pooling/41378/2 "2019-01-24T04:22:43Z")

</div>

This practice is not necessary in Defold. It’s automatically done for you. The reason why it’s automatic is that in your game.project you set the max of everything you want, and then those are reused.

Create/destroy objects at will. There is no issue for this in Defold.

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [January 24, 2019, 4:54am UTC](https://forum.defold.com/t/how-to-use-object-pooling/41378/3 "2019-01-24T04:54:50Z")

</div>

As @Pkeod says there really is no need to manually pool your objects. I created an example a long time ago that shows this: [publicexamples/examples/pooling\_vs\_creating at master · britzl/publicexamples · GitHub](https://github.com/britzl/publicexamples/tree/master/examples/pooling_vs_creating)

---

<div class="post-metadata">

**Author:** ![Alex\_8BitSkull](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/alex_8bitskull/32/5424_2.png) [@Alex\_8BitSkull](https://forum.defold.com/u/Alex_8BitSkull)\
**Post date:** [January 24, 2019, 10:48am UTC](https://forum.defold.com/t/how-to-use-object-pooling/41378/4 "2019-01-24T10:48:11Z")

</div>

Is there a performance hit in setting really high limits in game.project?

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [January 24, 2019, 11:24am UTC](https://forum.defold.com/t/how-to-use-object-pooling/41378/5 "2019-01-24T11:24:01Z")

</div>

> [@Alex\_8BitSkull](#):
>
> Is there a performance hit in setting really high limits in game.project?

It will allocate more memory. But if you set 10000 as limit and use only 10 it would not traverse all 10000 so from an update perspective there shouldn’t be any difference.

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [January 24, 2019, 12:08pm UTC](https://forum.defold.com/t/how-to-use-object-pooling/41378/6 "2019-01-24T12:08:10Z")

</div>

A recommendation is to never set higher limits than you know that you will use. Use the profiler or make manual calculations and then set limits based on your findings.

---

<div class="post-metadata">

**Author:** ![Alex\_8BitSkull](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/alex_8bitskull/32/5424_2.png) [@Alex\_8BitSkull](https://forum.defold.com/u/Alex_8BitSkull)\
**Post date:** [January 24, 2019, 12:16pm UTC](https://forum.defold.com/t/how-to-use-object-pooling/41378/7 "2019-01-24T12:16:03Z")

</div>

Thanks, that’s a great idea!

---

<div class="post-metadata">

**Author:** ![Xev](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/xev/32/41556_2.png) [@Xev](https://forum.defold.com/u/Xev)\
**Post date:** [July 29, 2026, 1:55pm UTC](https://forum.defold.com/t/how-to-use-object-pooling/41378/8 "2026-07-29T13:55:28Z")

</div>

I downloaded the benchmark out of curiosity and tried to eliminate as many variables as possible that could affect the result. My findings are that it does make a difference when you’re dealing with thousands of game objects.

On average it is twice as fast to move game objects in and out of a pool, than creating and destroying them. However, it uses up almost twice the memory. That could be because of my implementation though, where I move the IDs from an active and inactive pool. The results are very consistent and only fluctuates roughly 1kB and at most 1ms.

**2500 Pooled game objects**  
Time: 3ms  
Memory: 350.94kB.

**2500 Created/Deleted game objects**  
Time: 6ms  
Memory: 194.68kB

![image](https://forum-defold-uploads.b-cdn.net/original/3X/0/a/0a44dab39727dd2b391c83c4fc2cc22fecb6b7ae.png)

It takes roughly 3 runs for the memory to stabilize. The first and second run can fluctuate a bit.

**Ran it on this system**  
CPU: 13th Gen Intel(R) Core™ i5-1335U (1.30 GHz)  
RAM: 16,0 GB  
iGPU: Intel(R) Iris(R) Xe Graphics (128 MB)  
Defold version: 1.13.0

I hope this can be helpful to anyone in the future. 🙂

---

<div class="post-metadata">

**Author:** ![selimanac](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/selimanac/32/6397_2.png) [@selimanac](https://forum.defold.com/u/selimanac)\
**Post date:** [July 29, 2026, 2:45pm UTC](https://forum.defold.com/t/how-to-use-object-pooling/41378/9 "2026-07-29T14:45:30Z")

</div>

> [@Xev](#):
>
> **2500 Pooled game objects**  
> Time: 3ms  
> Memory: 350.94kB.
> 
> **2500 Created/Deleted game objects**  
> Time: 6ms

Just guessing, but the time difference is probably because of the Lua → C overhead. AFAIK, they are not allocated and freed on the C side for every GO create/delete, they are already pooled. If you try creating and deleting them entirely in C using the SDK, you’ll probably get less than half the Lua. I don’t know how you profiled them, but those numbers also seem a little too high to me.

---

<div class="post-metadata">

**Author:** ![Xev](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/xev/32/41556_2.png) [@Xev](https://forum.defold.com/u/Xev)\
**Post date:** [July 29, 2026, 2:50pm UTC](https://forum.defold.com/t/how-to-use-object-pooling/41378/10 "2026-07-29T14:50:50Z")

</div>

Yes that would be my assumption too.

I started it with the benchmark linked to in this thread, then I tried to strip it down as much as possible, localizing global functions, and reusing tables, removing animations, etc.

> **[publicexamples/examples/pooling\_vs\_creating at master · britzl/publicexamples](https://github.com/britzl/publicexamples/tree/master/examples/pooling_vs_creating)**
>
> master/examples/pooling\_vs\_creating

The initial benchmark used more CPU and memory, roughly 9ms and 1MB for the create/delete code path.
