From: Ralph Shnelvar Date: 2009-11-24T07:27:06+09:00 Subject: Re: More on psuedo arrays; Better way? Symbols v. Strings >> MLK> Do you know the difference between symbols and strings? A million >> MLK> strings may be generated (and quickly GC'd), but only 20 symbols will. >> I thought I did ... but apparently I didn't. >> I see that >> irb(main):001:0> "xyz01".to_sym.object_id >> => 156018 >> irb(main):002:0> ("xyz%02d" % 1).to_sym.object_id >> => 156018 >> So .... >> Do symbols hang around "forever"? Once a symbol is >> created it is not deleted until the interpreter goes away? SPS> It depends on the interpreter – but in MRI MRI? SPS> the Symbols stay forever. SPS> That’s why Rails uses Strings as keys in the params Hash¹; if Symbols SPS> were used, you could theoretically create a denial of service attack by SPS> making requests with a lot of unique GET parameters (which Rails would SPS> turn into Symbols and MRI would not garbage-collect). Wow ... that's really interesting. Thank you for your interesting and informative response. So given that one could accumulate and accumulate and accumulate symbols ... what is the point of symbols? Are they really needed in Ruby and/or Rails?