stateHistoryLimit property

int stateHistoryLimit
final

The maximum number of states that can be stored in the history.

Note: Setting a very high value for stateHistoryLimit can potentially overload the system's RAM. This is because each state stored in the history consumes memory, and if the number of states is excessively high, it can lead to memory exhaustion and eventually cause the application to crash.

For example, the list that stores the history from screenshots as Uint8List. Each Uint8List object can represent a substantial amount of binary data. If the history limit is set too high, the cumulative memory usage of all these screenshots can quickly add up, leading to an out-of-memory error.

The exact amount of RAM consumed depends on the size of each Uint8List and the value of stateHistoryLimit. For instance, if each screenshot is 1 MB in size, and stateHistoryLimit is set to 10,000, the total memory usage for the history alone would be approximately 10 GB (10,000 * 1 MB). Such high memory usage can easily exhaust the available RAM on some systems.

It is advisable to set stateHistoryLimit to a reasonable value that balances the need for historical data with the available system resources.

Example:

// Setting a reasonable history limit to prevent RAM overload.
final int stateHistoryLimit = 100;

Implementation

final int stateHistoryLimit;