From: Jacek Olszak Date: 2005-11-09T17:56:20+09:00 Subject: Re: Question about symbols Thanks everyone for replies. I've got it :D Now I know why should I use symbols. Regards Jacek On Wed, 09 Nov 2005 09:32:12 +0100, Robert Klemme wrote: > mental@rydia.net wrote: >> Quoting Robert Klemme : >> >>> 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 > > > > -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/