[id='configure_off_heap-{context}']
= Using Off-Heap Memory
Configure {brandname} to store cache entries in native memory outside the JVM
heap space.

.Procedure

. Modify your cache configuration to use off-heap memory.
+
* Declarative: Add the `storage="OFF_HEAP"` attribute to the `memory` element.
* Programmatic: Call the `storage(OFF_HEAP)` method in the `MemoryConfigurationBuilder` class.
+
. Limit the amount of off-heap memory that the cache can use by configuring either `max-count` or `max-size` eviction.

[discrete]
== Off-heap memory bounded by size

.Declarative configuration
[source,xml,options="nowrap",subs=attributes+,role="primary"]
----
include::config_examples/max_size_offheap.xml[]
----

.Programmatic configuration
[source,java,options="nowrap",subs=attributes+,role="secondary"]
----
include::code_examples/MaxSizeOffHeap.java[]
----

[discrete]
== Off-heap memory bounded by total number of entries

.Declarative configuration
[source,xml,options="nowrap",subs=attributes+,role="primary"]
----
include::config_examples/max_count_offheap.xml[]
----

.Programmatic configuration
[source,java,options="nowrap",subs=attributes+,role="secondary"]
----
include::code_examples/MaxCountOffHeap.java[]
----

[role="_additional-resources"]
.Additional resources
* link:{configdocroot}[{brandname} Configuration Schema Reference]
* link:{javadocroot}/org/infinispan/configuration/cache/MemoryConfigurationBuilder.html[org.infinispan.configuration.cache.MemoryConfigurationBuilder]
