From: Marnen Laibow-Koser Date: 2009-11-24T23:25:32+09:00 Subject: Re: More on psuedo arrays; Better way? Symbols v. Strings Ralph Shnelvar wrote: [...] > SPS> It depends on the interpreter – but in MRI > > MRI? Matz's Ruby Interpreter (the standard 1.8 implementation). > > 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 ... Only if their string representations are different. But the Rails consideration is sort of a special case. > what is the point of symbols? The point is that :abc is guaranteed to refer to the same object every time, whereas "abc" creates a new object every time. Normally, this means that symbols are more efficient. > Are they really needed in > Ruby and/or Rails? Absolutely. Message passing uses symbols for the message names. If it used strings instead, the interpreter would quickly bog down, since every method call in Ruby is implemented with message sending. You're asking fairly basic questions that a close reading of the Pickaxe Book should answer... Best, -- Marnen Laibow-Koser http://www.marnen.org marnen@marnen.org -- Posted via http://www.ruby-forum.com/.