It is well known that the minimal space overhead for a non-immediate object in
Ruby is 20 bytes*1.
But the overhead will be much higher if your object happens to have
instance variables (read: almost always).
Take for instance
class Stupid;attr_accessor:fooendclass Stupid2;attr_accessor:foo,:barendo1=Stupid.newo1.foo=1o2=Stupid2.newo2.foo=1o2.bar=2
o1 will take around
and o2 bytes, i.e. for objects with under 55 instance
variables, the memory footprint is around 100 bytes plus 20 bytes per
instance variable --- that's quite heavy.
The exact numbers depend on the behavior of malloc regarding memory alignment
and overhead. Doug Lea's malloc,
in wide use, takes 8 or 4 bytes per chunk.
Here are some other overheads for Arrays, Hashes, etc. (+M denotes the malloc
overhead per allocated chunk, normally 4 or 8 bytes):