From: Eric Hodel Date: 2007-09-24T11:16:03+09:00 Subject: Re: Object's allocated memory On Sep 23, 2007, at 09:15, crb002@gmail.com wrote: > I have an application where I need to sort objects based on their > memory footprint. What is the easiest way to get this information > from Ruby1.6 ? I have no problem with having to call some C functions > to get this info. > > The hack Marshal.dump(foo).size() would work, but since this might be > called often I need an elegant solution. Look at the mem_inspect gem. It has hooks into the GC for Ruby 1.8. Marshal.dump(foo).size will include all the memory an object references, including the object's instance variables & etc. The Array ['x'*1024] takes up only a few bytes of memory, but Marshal.dump.size says 1032 bytes. -- Poor workers blame their tools. Good workers build better tools. The best workers get their tools to do the work for them. -- Syndicate Wars