I use erts_debug:size/1
to calculate the memory for atom in erlang VM, but i find that the output is zero. Who can explain the reason?
7> erts_debug:size(true).
0
I use erts_debug:size/1
to calculate the memory for atom in erlang VM, but i find that the output is zero. Who can explain the reason?
7> erts_debug:size(true).
0
In docs, you can read:
The keyword here is HEAP. Process has stack and heap. There is a great presentation, that shows you, what gets stored on the heap and what on the stack, when a term is created (start reading from page 8).
http://www.erlang-factory.com/upload/presentations/467/Halfword_EUC_2011.pdf
Basically, when you create a single atom. There is nothing on the heap and a one word pointer on the stack. It points to the atom table, which also consumes memory and is not garbage collected (never create atoms dynamically in your application!). Source: http://www.erlang.org/doc/efficiency_guide/processes.html
The reason is that atoms are interned in the atom table together with the data for the atom so there is only one copy of an atom in the whole node. This means that in your data the atom is just a tagged reference in to the atom table and takes no space. Hence the size is zero.
So it is not an inconsistency or bug.