For any Julia variable, I wish to check how much memory it uses just to exist.
The docstring of sizeof states: Size, in bytes, of the canonical binary representation of the given DataType T, if any. Or the size, in bytes, of object obj if it is not a DataType.
However:
Is this functionality implemented in another function? Also, how would it be possible to capture the size of arrays of pointers (other than manual sum(sizeof(x) for x in xx))?
julia> sizeof([[1,2,3,4,5],[6,7,8],[9,10]])
24 # should be 80 = (5+3+2)*8
help?> Base.summarysize
Base.summarysize(obj; exclude=Union{...}, chargeall=Union{...}) -> Int
Compute the amount of memory, in bytes, used by all unique objects reachable
from the argument.
Keyword Arguments
≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
• exclude: specifies the types of objects to exclude from the
traversal.
• chargeall: specifies the types of objects to always charge the
size of all of their fields, even if those fields would normally
be excluded.
See also sizeof.
Examples
≡≡≡≡≡≡≡≡
julia> Base.summarysize(1.0)
8
julia> Base.summarysize(Ref(rand(100)))
848
julia> sizeof(Ref(rand(100)))
8
sizeof is only useful to most users for bits types and is the same as summarysize on these. Other types do not have a defined layout so their sizeof is exposing internal implementation details.
Part is the array header which contains e.g. the size of the array and the dimensions. You can check the size of an empty array is actually 40.
This explains your second example exactly and accounts for most of the memory of the other examples. In case of the sparse array there are 2 more fields in the struct for the size I think.