From: "Shot (Piotr Szotkowski)" Date: 2009-11-24T04:04:33+09:00 Subject: Re: More on psuedo arrays; Better way? Symbols v. Strings --PNTmBPCT7hxwcZjr Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Ralph Shnelvar: > 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 wil= l. > I thought I did ... but apparently I didn't. > I see that > irb(main):001:0> "xyz01".to_sym.object_id > =3D> 156018 > irb(main):002:0> ("xyz%02d" % 1).to_sym.object_id > =3D> 156018 > So .... > Do symbols hang around "forever"? Once a symbol is > created it is not deleted until the interpreter goes away? It depends on the interpreter =E2=80=93 but in MRI the Symbols stay forever. That=E2=80=99s why Rails uses Strings as keys in the params Hash=C2=B9; if = Symbols were used, you could theoretically create a denial of service attack by making requests with a lot of unique GET parameters (which Rails would turn into Symbols and MRI would not garbage-collect). =C2=B9 Rails actually uses HashWithIndifferentAccess that lets you access its elements using Symbol keys as well =E2=80=94 Shot --=20 Founding member of the Hyphenation Society, a grassroots-based, not-for-profit, locally-owned-and-operated, cooperatively-managed, modern-American-English-usage-improvement association. [Rick Moen] --PNTmBPCT7hxwcZjr Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAksK3JwACgkQi/mCfdEo8Uq5HACfYHC1AmgIiA4GLbFvcurwPvMg 7qsAoLw3l4wmmyVZLpC74EQqFASWRVfD =mdhX -----END PGP SIGNATURE----- --PNTmBPCT7hxwcZjr--