I have been on this list for about a year. I have noticed that many
newcomers with lower level language background such as C are cautious
about this whole automatic memory management and/or the overhead of a
dynamic language. So, I'll start the FAQ. Please join in.

----------------------------------------------------------------------
Q. Why does an array of integer consumes at least thrice as many
storage compared to C's array of integer?

A. Because the array does not store the integer directly, but rather
stores a pointer to an integer (FixNum) object.

----------------------------------------------------------------------
Q. Why does ruby program so memory inefficient? 

A. One is because the full interpreter must be running too as it is a
dynamic language; one never knows whether a new method is going to be
defined at runtime. The other is because there is some metadata that
needs to be keep around in order to interpret a bunch of seemingly
random data.

----------------------------------------------------------------------
Q. I need to encrypt/hide/obfuscate the source code

A. There is already a page on this in www.rubygarden.com

----------------------------------------------------------------------
Q. What's the memory size of each object?

A. That varies. But ruby.h contains the size of some standard objects
such as Object, Fixnum, Array, Struct, String, etc.

----------------------------------------------------------------------
Q. But I'm concerned about the memory footprint size!

A. Perhaps you are using the wrong language. Have you considered using
another language with manual memory management? If you are already
attached to ruby, then do you know about the C-language binding? You
can implement the section that requires careful memory management in
C and the rest in ruby.

----------------------------------------------------------------------
Q. How fast is GC?

A. How fast does it take to change bit 0 to 1? Seriously, in ruby, GC
is performed everytime the pre-allocated memory pool is exhausted. It
uses a variation of the mark and sweep algorithm. This part is often
fast. However, if after GC there is still not enough memory for the
new object, then ruby will perform a realloc on its memory pool. This
part is often slow. 

So, as in other languages with GC, to optimise the performance of GC,
do not create excessive intermediate objects.


----------------------------------------------------------------------
Q. In Java, you can set the initial memory pool to a certain
size. What's the equivalent in ruby?

A. Setting the initial memory pool to a certain size decreases
start-up time if the code creates many objects because it postpones
realloc. There is no equivalent to this in ruby (yet?).