Joel VanderWerf
7/19/2007 2:50:00 AM
Stephen Cox wrote:
> yeah I figured out symbols were the actual value. But one question, if a
> symbol is no longer used what happens to it? Is it released when the
> procedure it was create in completes?
No. Symbols accumulate forever. They cannot be garbage collected in
current ruby. A variable whose value is a symbol actually contains a
number, which is an index into a table, rather than the characters of
the symbol. Ruby has to ensure that, as long as the program runs, this
table entry contains the same string:
irb(main):003:0> :a.to_i
=> 14033
irb(main):004:0> 14033.to_sym
=> :a
This is another reason to use strings for most purposes. (Also, strings
look better in YAML, especially as hash keys.)
--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407