Memory Usage

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 TypeMemory Size
Small integer1 word.
On 32-bit architectures: -134217729 < i < 134217728 (28 bits).
On 64-bit architectures: -576460752303423489 < i < 576460752303423488 (60 bits).
Large integerAt least 3 words.
Atom1 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.
FloatOn 32-bit architectures: 4 words.
On 64-bit architectures: 3 words.
Binary3-6 words + data (can be shared).
List1 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.
Tuple2 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.
Pid1 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.
Port1 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.
ReferenceOn 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.
Fun9..13 words + the size of environment.
A fun refers into a fun table, which also consumes memory.
Ets tableInitially 768 words + the size of each element (6 words + the size of Erlang data). The table grows when necessary.
Erlang process338 words when spawned, including a heap of 233 words.

Table: Memory Size of Different Data Types

close