Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardRubyobject memory RVALUE embedded stringsSingle-choice MCQ

On a 64-bit CRuby with the default GC slot size, why does ObjectSpace.memsize_of report 40 bytes for a short string like "hello" but a much larger value once you append enough bytes to it?

require 'objspace' s = "hello" ObjectSpace.memsize_of(s) # => 40 s << ("x" * 200) ObjectSpace.memsize_of(s) # => much larger