• Hello
Search Results for

    Show / Hide Table of Contents

    Introduction

    Object pooling is a common pattern in game development. It helps you reuse game objects instead of creating and destroying them over and over.

    The idea is simple: you keep a pool (a collection) of ready-to-use objects. When you need one, you take it from the pool. When you are done with it, you put it back. This is really helpful when objects are created and destroyed a lot, like bullets, enemies, or particles.

    Here is how object pooling works, step by step:

    • Initialization: Create a set of objects up front (turned off and stored in a pool), or create them the first time you need them.

    • Usage: Instead of making a new object, take one from the pool, turn it on, and place it where you need it.

    • Deactivation: When you no longer need an object, turn it off and put it back in the pool so you can use it again later, instead of destroying it.

    By reusing objects this way, you avoid the extra work of constantly creating and destroying them. This can give your game a nice performance boost.

    Performance

    A big part of optimizing your game is keeping it fast and smooth. That means avoiding sudden frame rate drops and cutting down on unnecessary memory use. Both of these help the garbage collector do less work, so your game runs smoothly and uses resources efficiently.

    Frames Per Second

    The image below shows the average minimum frames per second (fps) over time, with and without pooling.

    Figure 1 - Line-Graph: Average minimum frames per second (fps) over time with and without pooling.

    The X-axis shows time (20 steps is about 1 second). The Y-axis shows frames per second. The green line is the average minimum fps with pooling. The blue line is without pooling. Why look at the minimum? Because the minimum fps shows the frame drops that players actually feel as stuttering or lag. You want your game to run as smoothly as possible.

    As the graph shows, pooling raises the minimum fps and keeps it steadier. The boxplot below makes this even easier to see.

    Figure 2 - Boxplot: Shows the average minimum frames per second (fps) as quartile and median.

    Memory Allocation

    Unnecessary memory use is another common cause of frame drops, because the garbage collector has to pause and clean up unused memory. Most of the time, you allocate memory when you instantiate new GameObjects or Components. The image below compares memory use with and without pooling.

    Figure 3 - Line-Graph: Comparison of memory allocation (MB) over time with and without pooling.

    The X-axis shows time (20 steps is about 1 second). The Y-axis shows allocated memory in megabytes. The green line is memory use with pooling, and the blue line is without pooling. With pooling, memory use stays roughly the same. Without pooling, memory use keeps growing over time. This can cause delays during allocation and garbage collection, or even crash your game if memory use gets too high.

    In This Article
    Back to top GuardingPearSoftware documentation