mental / rydia.net wrote:
> Quoting Robert Klemme <bob.news / gmx.net>:
>
>> Because they are immutable, fast and less memory consuming.  They
>> are typically used for a limited and known set of keys.
>
> Well, they consume memory differently -- not necessarily less.

There are two reasons why I wrote about higher memory consumption for
strings:

1. If you have a string constant in your code like "foo" or 'bar' then the
constant takes up memory and each evaluation creates a new String object.
Although they share the internal char buffer there is some memory
overhead.  You can easily try it:

>> 5.times { puts "foo".object_id }
135178740
135178716
135178620
135178488
135178464
=> 5

2. If stored in multiple places then there's still only one symbol but
multiple strings.  Even worse, if those strings stem from different
sources they won't even share their char buffer.

> Symbols are never garbage-collected, so you should not use them for
> situations where you could have an unbounded number of unique
> symbol values.

That's why I recommended to use them with a limited set of values only.

Hope that makes things a bit clearer.

Kind regards

    robert