> ## Documentation Index
> Fetch the complete documentation index at: https://docs.activeviam.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How Atoti uses and releases memory

> How Atoti divides data, indexes, and aggregate providers between heap and off-heap memory, why memory usage stays high after deletion without being a leak, and how the allocator cache, index rebuilds, and cube schema rebuilds reclaim it.

Atoti keeps its data, and the structures that speed up queries, in both heap and off-heap memory.
Knowing which structure lives where explains why memory usage can stay high after data is deleted.
This page builds on [How JVM tuning can improve Atoti performance](https://docs.activeviam.com/concepts/performance/jvm-tuning.md), which introduces the two memory areas.

## Which structures use heap memory and which use off-heap memory?

By default, Atoti stores most data and indexes off-heap, and keeps object values and temporary query objects on the heap.

* **Off-heap memory:** Numeric values, datastore indexes, references, and the pre-aggregated data of aggregate providers.
* **Heap memory:** Object values such as text and dates, bitmap indexes, and the temporary objects that queries create.

A debugging-only JVM setting can keep all stored data on the heap.
It applies to both the Atoti Java SDK and the Atoti Python SDK.

## Which structures take the most memory?

* **Datastore indexes:** A datastore index finds the records that match given field values, without scanning the whole store. Each index grows with the number of records. See [How to index stores with Atoti Java SDK](https://docs.activeviam.com/engine/java-sdk/latest/datastore/store_indexing.md).
* **References:** A reference links the records of one store to the matching records of another store. Each reference also grows with the number of records. See [What is a database schema?](https://docs.activeviam.com/concepts/database/database-schema.md)
* **Bitmap indexes:** A bitmap aggregate provider uses a bitmap index to find the cells that match each hierarchy member. Each bitmap index grows with the number of hierarchies and with the number of members in each hierarchy. See [How aggregate providers can speed query time](https://docs.activeviam.com/concepts/performance/aggregate-providers.md#bitmap-provider).

## How is memory impacted by data deletion?

1. **Atoti frees the memory of deleted records once nothing uses them:** It waits until no running query or retained version still uses those records. Memory is freed one chunk at a time. A chunk is freed when all its rows are deleted, and compacted when enough of its rows are deleted.

   * A long-running query keeps the records it reads until the query ends.
   * A retained version keeps its records, even after they are deleted from the latest version.

   Keeping fewer versions frees memory sooner. See [How Atoti manages data versioning](https://docs.activeviam.com/concepts/versions/versions.md).
2. **Freed memory goes into the allocator cache, up to a maximum size:** The maximum size is a share of the maximum off-heap memory. Above that size, freed memory returns to the operating system.
3. **Atoti reuses the cached memory for new data:** For example, the data of the next as-of date reuses the memory of the deleted one. The cache does not need to be cleared.
4. **Memory usage stays high, but this is not a leak:** The operating system and monitoring tools still count cached memory as used by Atoti.
5. **Indexes and other structures are append-only:** Deleting records marks them as deleted, but these structures keep them:

   * Datastore indexes.
   * References.
   * Dictionaries, which store each distinct value of a field once.
   * Point indexes, which locate the pre-aggregated cells of aggregate providers.
   * Bitmap indexes.

   Only a manually triggered rebuild removes the deleted records from datastore indexes, point indexes, and bitmap indexes.

## Can memory be reclaimed?

A memory analysis report shows which stores, indexes, and aggregate providers use the most memory.
See [Memory analysis report](https://docs.activeviam.com/engine/java-sdk/latest/monitoring/off-heap_memory.md#memory-analysis-report).
Read the report first to decide which of the following actions applies.

> [!WARNING]
>
> Rebuilding indexes or a cube schema takes significant processing time and memory.
> While a rebuild runs, no data can be loaded into any store.
> An index rebuild keeps only the latest version of the data on each branch. Older versions are permanently lost.
> Run rebuilds during quiet periods, such as outside business hours.

Three actions reclaim memory:

* **Reduce or turn off the allocator cache (JVM setting):** Freed memory then returns to the operating system, for use by other processes. Later data loads must request that memory again. See [Properties in Atoti Server](https://docs.activeviam.com/engine/java-sdk/latest/properties/ap_properties.md#other-atoti-properties).
* **Rebuild the datastore indexes of large stores (Atoti Java SDK):** The rebuilt indexes contain only the records that remain in the store. See [Rebuild indexes](https://docs.activeviam.com/engine/java-sdk/latest/datastore/store_indexing.md#rebuild-indexes).
* **Rebuild the cube schema (Atoti Java SDK):** The rebuild recreates the point indexes and bitmap indexes of aggregate providers.

Rebuilds alone do not always return memory to the operating system. Combine a rebuild with turning off the allocator cache.

## Related reading

* [How to manage memory with Atoti Java SDK](https://docs.activeviam.com/engine/java-sdk/latest/configuration/memory_management.md)
* [How to monitor off-heap memory with Atoti Java SDK](https://docs.activeviam.com/engine/java-sdk/latest/monitoring/off-heap_memory.md)
* [How to tune JVM settings with Atoti Python SDK](https://docs.activeviam.com/engine/python-sdk/latest/getting_started/deployment/deployment_setup.md#java-options)
* [How JVM tuning can improve Atoti performance](https://docs.activeviam.com/concepts/performance/jvm-tuning.md)
* [How aggregate providers can speed query time](https://docs.activeviam.com/concepts/performance/aggregate-providers.md)
