> For the complete documentation index, see [llms.txt](https://docs.flatredball.com/flatredball/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.flatredball.com/flatredball/api/flatredball/spritemanager/maxparticlecount.md).

# MaxParticleCount

### Introduction

The SpriteManager performs pooling on its particle [Sprites](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php) to prevent continual memory allocation. The MaxParticleCount property controls the size of the pool. A larger pool means that more particle [Sprites](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php) can live at one time; however, it also means that the game will require more memory at runtime to store extra [Sprites](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php).

### Code Example

MaxParticleCount defaults to a value of 2,900 at the time of this writing. This following code increases the maximum number of particles to 4,000.

```
SpriteManager.MaxParticleCount = 4000;
```

### Why are particles pooled?

Particles generally have short lives and are created at a frequent interval. If all particles were allocated when needed and destroyed when not, this would result in a considerable amount of memory allocation and would cause the garbage collector to work more frequently than necessary. The garbage collector can cause significant hops in frame rate on the Xbox 360 and in Silverlight.

### Why doesn't the engine automatically grow MaxParticleCount?

Usually the only time you need to grow MaxParticleCount is if you have created more particles (or anticiapte creating more) than the default MaxParticleCount value. You may be wondering why the engine doesn't simply expand this list as more particles are needed. There are two main reasons:

1. Expanding the list requires allocation. If the engine were to automatically expand the internal pool, this would likely be done in the middle of game play. All (or as much as possible) allocation should be done when a [Screen](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php) is loaded and not during its Activity to prevent the garbage collector from working.
2. The MaxParticleCount can be used to catch bugs where particle [Sprites](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php) are created but not destroyed. For example, if you have a single [Emitter](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php), but after 1 minute of emission you hit the MaxParticleCount, then it's likely that you are not removing emitted particles. If the engine automatically expanded the list, this bug would result in worse and worse frame rate - a symptom which doesn't lead you to the problem as quickly as an exception.


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.flatredball.com/flatredball/api/flatredball/spritemanager/maxparticlecount.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
