Skip to content
class method

ObjectSpace.memsize_of

(untyped) -> ::Integer
ObjectSpace.memsize_of(obj) → Integer

Return consuming memory size of obj in bytes.

Note that the return size is incomplete. You need to deal with this information as only a HINT. Especially, the size of T_DATA may not be correct.

This method is only expected to work with CRuby.

From Ruby 3.2 with Variable Width Allocation, it returns the actual slot size used plus any additional memory allocated outside the slot (such as external strings, arrays, or hash tables).