From: David Masover Date: 2008-06-18T15:26:26+09:00 Subject: Re: Can I find out the memory used by an object? On Tuesday 17 June 2008 10:53:56 Robert Klemme wrote: > Typically you would rather be interested in a particular part of the > object graph that is reachable from an instance - and here it becomes > difficult, because any object can have any number of references and > can be referred to any number of times. Where then do you count the > memory? Or do you count it multiple times? etc. I think this is analagous to a filesystem structure. It is possible to do roughly all of the above with tools like ls and du -- for example, 'ls -l' will show the logical size of each file, but also a total that represents the sum of the actual disk space allocated for each file -- that is, "logical size" might show a file as being larger than the filesystem it's on, so long as it's a sparse file. But it will count hardlinks twice in that total. It also isn't deep -- it might show the space used to store a particular subdirectory, but not the space used by the actual files in that subdirectory. And then there's 'du', which will show the total, real size used for any directory tree, recursively, counting each inode only once (so hardlinked files aren't counted twice). I would argue that tools like these would be useful in Ruby, even if there have to be many twitchy options to control how it is counted. But then, I've always been more for letting Ruby take as much RAM as it wants until I run out, and then start optimizing.