Answer the question
In order to leave comments, you need to log in
In Ruby version 2.2, how do you find out the size of the memory occupied by an object?
I decided to ask how much memory the array eats, but I never googled the answer. Among the answers were not relevant for version 2.2.
Answer the question
In order to leave comments, you need to log in
You need to include the ObjectSpace standard library.
The ObjectSpace module has a memsize_of(obj) method.
require 'objspace'
hash = {a: 1, b: 2}
ObjectSpace.memsize_of(hash)
# => 240
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question