> For the complete documentation index, see [llms.txt](https://netick.gitbook.io/v1/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://netick.gitbook.io/v1/network-object-instantiation-and-destruction/network-prefab-pool.md).

# Network Prefab Pool

Object pooling is a very effective technique to avoid run-time allocations (and thus, improve performance), by creating a pool of objects of the same type, at the start of the game. So that when you want to instantiate a certain prefab, you will not create a new object in memory. But rather, all instances of that prefab are already created, and you simply grab one out of the pool and initialize it. And when you want to destroy an instance, instead of removing it from memory (which causes GC), you put it back on the pool – recycling it.\
\
Pooling is extremely useful and effective if you have a prefab in your game that you instantiate and destroy repeatedly. For instance, the bomb in Bomberman.\
\
Netick has a built-in pooling system that you can use.\
\
By default, all prefabs are not pooled. To enable pooling for a certain prefab, you must call `InitializePool` **(must be called at the start of Netick in NetworkEventsListner)** on that prefab and pass it the initial amount to create:<br>

```csharp
public override void OnStartup(NetworkSandbox sandbox)
{
     var bombPrefab = sandbox.GetPrefab("Bomb");
     sandbox.InitializePool(bombPrefab, 5);
}
```

{% hint style="info" %}
Check out the Bomberman sample if you are confused. It demonstrates pooling of the bomb prefab.
{% endhint %}

And if this amount happens to be exceeded, Netick will simply create more objects in the pool automatically.

And you don’t need to use special instantiate or destroy methods to deal with pooled prefabs, it all works through the same `Sandbox.NetworkInstantiate` and `Sandbox.Destroy` methods.\
\
Although you still need to reset your objects. However, Netick automatically resets all network properties to their declaration values.

#### Resetting Prefab Instances

To reset your object, override NetworkReset on your class inheriting from NetworkBehaviour:

```csharp
public override void NetworkReset()
{
     // reset all non-networked state which need to be reset so that your object is ready to be used again
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://netick.gitbook.io/v1/network-object-instantiation-and-destruction/network-prefab-pool.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
