# 13.6 Engine limits

> Limits are resources set by whoever runs the program —depth, statements, memory, time— and are not part of the language: a program that does not reach them gives the same result under any configuration.

Web page: https://pseudolearn.app/en/spec/motor/limites

> **In one sentence**
>
> Limits are resources set by whoever runs the program —depth, statements, memory, time— and are not part of the language: a program that does not reach them gives the same result under any configuration.

## 13.6.1 How it works

| Limit | Measured in | When exhausted |
| --- | --- | --- |
| depth | active frames | failure `recursionDepthExceeded` |
| cells | live heap values | failure `cellLimitExceeded` |
| statements | statement entries | cut `statementBudgetExhausted` |
| time | the host's clock | cut without a diagnostic |
| live tasks | spawned, unfinished tasks | failure `taskLimitExceeded` |

The units are **deterministic**: they do not depend on the machine. An object takes one cell plus one per attribute; an array, one plus one per element; a text created at run time, one plus one per eight characters. Literals and what `Write` prints take no cells.

**Figure 13.6-1: Capped resources**

Four bars: depth, full and marked as exhausted; cells, statements and time, partly full.

Four resources with their cap. Exhausting depth or cells is a program failure; exhausting statements or time is a limit cut.

### Program: A recursion that exhausts depth

```pseudolearn
Subroutine Bajar(n As Integer) As Integer
  Return Bajar(n + 1) + 1;
EndSubroutine

Algorithm Profundo
  Write Bajar(0);
EndAlgorithm
```

**Diagnostics**
- `recursionDepthExceeded` (error, 2:10): Recursion depth limit reached: 100000

*The program finishes with an error.*

> **Limit**
>
> - Every host allows at least 1000 frames and 4194304 cells.
> - The app uses 1000 frames; the terminal, 100000 and no statement budget.
> - No limit exhausts the host's stack or produces an internal failure.
> - Network and JSON limits do not end the program: they arrive as error values.

**In short**
- Limits are configured by the host; they are not part of the language.
- They are measured in deterministic units.
- Depth and cells fail; statements and time cut.

**See also**
- [7.7 Recursion](https://pseudolearn.app/en/spec/subprogramas/recursion.md)
- [13.2 Memory and the collector](https://pseudolearn.app/en/spec/motor/memoria.md)
