[id='off-heap-memory_{context}']
= JVM heap and off-heap memory

{brandname} stores cache entries in JVM heap memory by default.
You can configure {brandname} to use off-heap storage, which means that your data occupies native memory outside the managed JVM memory space.

The following diagram is a simplified illustration of the memory space for a JVM process where {brandname} is running:

.JVM memory space
image::jvm_memory_space.png[This diagram depicts the JVM memory space divided into heap and off-heap memory.]

[discrete]
== JVM heap memory

The heap is divided into young and old generations that help keep referenced Java objects and other application data in memory.
The GC process reclaims space from unreachable objects, running more frequently on the young generation memory pool.

When {brandname} stores cache entries in JVM heap memory, GC runs can take longer to complete as you start adding data to your caches.
Because GC is an intensive process, longer and more frequent runs can degrade application performance.

[discrete]
== Off-heap memory

Off-heap memory is native available system memory outside JVM memory management.
The _JVM memory space_ diagram shows the `Metaspace` memory pool that holds class metadata and is allocated from native memory.
The diagram also represents a section of native memory that holds {brandname} cache entries.

Off-heap memory:

* Uses less memory per entry.
* Improves overall JVM performance by avoiding Garbage Collector (GC) runs.

One disadvantage, however, is that JVM heap dumps do not show entries stored in off-heap memory.
