From: Robert Hulme Date: 2008-06-17T18:54:35+09:00 Subject: Can I find out the memory used by an object? I'm 99% sure the answer to that question is no, but I thought I'd ask anyway :-) Practically speaking it's only of use to me if it can be done on MRI (Ruby 1.8). Trivially I can do something like (apologies for the hackiness, and not using the sysutil gem): def memory_used File.read("/proc/#$$/status").match(/^VmSize:\s*(\d*)/)[1].to_i end mem_used = memory_used() mem_used_since = memory_used - mem_used # Returns difference in KB since mem_used was set But that only tells me something about the Ruby process, not a particular object. The reason I ask is because I would like to create a cache object that stores complex objects, but is smart enough to remove the oldest things in the cache when the cache is using more than a certain amount of memory. I could Marshall.dump the objects and work out something crudely that way, but the reason I want the cache in the first place is because Marshall.dump and Marshall.load is too time expensive :-) Thanks -Rob -- George Carlin - "Frisbeetarianism is the belief that when you die, your soul goes up on the roof and gets stu...