From: Michael Neumann Date: 2008-05-09T01:06:57+09:00 Subject: Re: Comparing String with Symbol Roger Pack wrote: >> I'd rather use to_sym instead of to_s. >> >> matz. > > I'd use either one except that [quoting Tim Harper] > > once a symbol is allocated, it is never garbage collected. > > This opens up a potential DOS attack: if you convert any user input to > symbols (via #to_sym or #intern), they could easily fill your symbol > space up and eat all of the available system memory. > > We'd all be wiser than I was a few minutes ago to keep this present when > deciding whether to use symbols or strings: > > http://blog.hasmanythrough.com/2008/4/19/symbols-are-not-pretty-strings > -- > > or, in other words > loop { rand(10000000).to_sym } > # uses up memory in a hurry :) This one isn't better, despite being shorter ;-) a = []; loop { a << 1 } Or in general, "loop { }" is not a very good idea... Couldn't resist ;-) Regards, Michael