R
R
Roman Mirilaczvili2016-11-29 11:16:48
ruby
Roman Mirilaczvili, 2016-11-29 11:16:48

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

1 answer(s)
A
Alexander Shvaikin, 2016-11-29
@2ord

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 question

Ask a Question

731 491 924 answers to any question