From: Rick DeNatale Date: 2009-03-30T20:56:26+09:00 Subject: Re: Symbols garbage collector in Ruby1.9, fixed? --0014853493402e917b046654c6bc Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Mon, Mar 30, 2009 at 4:09 AM, I=F1aki Baz Castillo wrote= : > Hi, in Ruby 1.8 there is an issue when adding more and more Symbols > since they remain in memory and are never removed. > > I'm doing a server in Ruby that receives messages with headers (From, > To, Subject, X-Custom-Header-1...) and after parsing I store the > headers in a hash using symbols as keys: > > headers =3D { > :from =3D> "alice@aaa.com", > :to =3D> "bob@bbb.com", > :"x-custom-header-1" =3D> "Hi there" > } > > I could use strings as keys instead of symbols, but I've checked that > getting a Hash entry is ~25% faster using Symbols. > > The problem is that I could receive custom headers so for each one a > new Symbol would be created. An attacker could send lots of custom > headers to fill the server memory and cause a denial of service. > Which is why Rails (actually activesupport) which implements a HashWithIndifferentAccess to allows using strings and symbols equivalently for hash access, uses the string form in the actual hash forgoing the acces= s performance in favor of safety. --=20 Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale --0014853493402e917b046654c6bc--