Memory size of immediate terms discrepency question

The Erlang GC docs talk about how immediate terms do not use any heap space.

Terms are created on the heap by evaluating expressions. There are two major types of terms: immediate terms which require no heap space (small integers, atoms, pids, port ids etc) and cons or boxed terms (tuple, big num, binaries etc) that do require heap space. Immediate terms do not need any heap space because they are embedded into the containing structure.

However, there’s also this table which lists small ints as 1 word of memory. But if I run,

erts_debug:size(1)

the result is 0. Similarly, if I check other immediate terms with that function, I end up getting n -1, where n is what appears in that table. The box terms seems to match up with the table.

So, I’m just wondering why the discrepancy?

Immediate terms do not need any heap space because they are embedded into the containing structure.

I take “containing structure” to be like a tuple, list etc. is that correct?

erts_debug:size/1 counts the amount of data a term uses on the heap. The efficiency guide counts how much memory a term uses in total (containing structure + heap).

Since erts_debug:size/1 is an undocumented internal function, its return value has not been polished to be as logical(?) as the official documentation.

Yes, and also the stack/register slot that the value is in.

2 Likes