On Tue, Mar 06, 2007 at 04:40:37PM +0900, Wes Gamble wrote:
> I'd like to be able to estimate how much memory a given object requires.
> What is the best/easiest way to do this?  One thing that occurred to me
> was the Marshal.dump the object to a file and look at that, although
> looking at a textual representation of the object could be significantly
> larger (I think).
> 
> Any advice is appreciated.

http://eigenclass.org/hiki.rb?ruby+space+overhead

A rule of thumb:

for normal objects the memory footprint is around 100 bytes plus 20 bytes per
instance variable (applies to objs. with <55 instance variables).

(Apply recursively if you want to consider referenced objects too.)

See the above link for more details regarding Arrays, Hashes, Symbols,
Structs, etc...

-- 
Mauricio Fernandez  -   http://eigenclass.org   -  singular Ruby
                        ** Latest postings **
Towards compatibility with Ruby 1.9: Rails, Rake, RubyGems...
  http://eigenclass.org/hiki.rb?porting-rails-to-ruby-1.9
Ruby interpreting Prolog' interpreting Lisp interpreting Lisp solving FizzBuzz
  http://eigenclass.org/hiki.rb?lisp-in-lisp-and-prolog-and-ruby