Search documentation of Erlang System Documentation

# Memory Usage

Copy Markdown View Source

A good start when programming efficiently is to know how much memory different data types and operations require. It is implementation-dependent how much memory the Erlang data types and other items consume, but the following table shows some figures for the `erts-8.0` system in OTP 19.0.

The unit of measurement is memory words. There exists both a 32-bit and a 64-bit implementation. A word is therefore 4 bytes or 8 bytes, respectively. The value for a running system can be determined by calling `erlang:system_info(wordsize)`.

Data Type | Memory Size
Small integer | 1 word. On 32-bit architectures: -134217729 < i < 134217728 (28 bits). On 64-bit architectures: -576460752303423489 < i < 576460752303423488 (60 bits).
Large integer | At least 3 words.
Atom | 1 word. An atom refers into an atom table, which also consumes memory. The atom text is stored once for each unique atom in this table. The atom table is not garbage-collected.
Float | On 32-bit architectures: 4 words. On 64-bit architectures: 3 words.
Binary | 3-6 words + data (can be shared).
List | 1 word + 1 word per element + the size of each element.
String | (is the same as a list of integers) 1 word + 2 words per character.
Tuple | 2 words + the size of each element.
Small Map | (up to 32 keys) 5 words + the size of all keys and values.
Large Map | (more than 32 keys) N x F words + the size of all keys and values. N is the number of keys in the Map. F is a sparsity factor that varies between 1.6 and 1.8 due to the probabilistic nature of the internal HAMT data structure.
Pid | 1 word for a process identifier from the current local node. On 32-bit: 6 words for a process identifier from another node. On 64-bit: 5 words for a process identifier from another node. A process identifier refers into a process table and a node table, which also consumes memory.
Port | 1 word for a port identifier from the current local node. 5 words for a port identifier from another node. A port identifier refers into a port table and a node table, which also consumes memory.
Reference | On 32-bit architectures: 4-7 words for a reference from the current local node, and 7-9 words for a reference from another node. On 64-bit architectures: 4-6 words for a reference from the current local node, and 6-7 words for a reference from another node. A reference also refers into more or less emulator internal data structures which also consumes memory. At a minimum it refers into the node tables.
Fun | 9..13 words + the size of environment. A fun refers into a fun table, which also consumes memory.
Ets table | Initially 768 words + the size of each element (6 words + the size of Erlang data). The table grows when necessary.
Erlang process | 338 words when spawned, including a heap of 233 words.

Table: Memory Size of Different Data Types

← Previous Page Drivers
Next Page → System Limits