# Memory Limits

### Persistent memory#

Each time a custom

series
is created, our servers have to store its values in memory, for future use.

During backtesting this is not an issue, as, when the backtest ends, we can safely forget about these values. They only live in memory for a couple of seconds.

However, when you run a strategy, it may continue to run for months on end. We keep the last 500 values in memory of each

series
you create.

This could quickly get out of hand, so we've imposed limits on persistent memory for exactly the same reasons as we talked about in Execution Speed Limits.

Every QuantScript strategy has a limit of 200KB of persistent memory. Each

series
you create takes up 8KB.

In simple terms, you can create up to 25 custom series within a single strategy.

Another case in which we persist values in whenever you use the

[]
time travel operator on a complex series based on
open
,
high
,
low
,
close
,
volume
,
day
or
time
. If a series is complex enough that recalculating its past values would not be trivial, QuantScript may choose to save its past values in memory so it can access them immediately whenever necessary.

Let's look at some examples:

1 # Nothing is persisted so far
2 simple = open + close + high + low
3
4 # We are accessing a past value of 'simple'
5 # However nothing is persisted as this is fast to calculate
6 prevSimple = simple[1]
7
8 # Let's use a for loop to build a complex series
9 complex = 0
10
11 for distance from 0 to 99
12 complex = complex + open[distance]
13
14 # At this point, the series 'complex' represents a sum of 100 numbers
15 # If we access past values, that summing happens again
16 # It happens behind the scenes, and with different (past) values
17 # Now imagine how expensive the following expression would be:
18 moreComplex = complex + complex[1] + complex[2] + complex[3] + complex[4]

If there was no persistence of values involved, QuantScript would have to add up 401 values to calculate the

moreComplex
series, and on every bar, too.

Thankfully, QuantScript detects this and persists past values of the

complex
series in memory. Now, calculating
moreComplex
means just adding up 5 numbers.

For every such series QuantScript decides to persist, another 8KB of persistent memory is taken up for your strategy.

You can see how much persistent memory is allocated for your strategy by referring to the Console below the QuantScript Editor, after calculating the strategy's backtest.

### Throwaway memory#

An additional limit we have imposed is a limit on throwaway(intrabar) memory - the memory that's allocated during the execution of a single bar. We're way more lax there - the limit is 8MB. Much higher, as this memory is cleared after each execution of the script.

Refer to the Console below the QuantScript Editor to find out how much throwaway memory your strategy allocates on average.