What is symbol GC and why should you care? Ruby 2.2 was just released and, in addition to incremental GC, one of the other big features is Symbol GC. If you’ve been around the Ruby landscape, you’ve heard the term “symbol DoS”. A symbol denial of service attack occurs when a system creates so many symbols that it runs out of memory. This is because, prior to Ruby 2.2, symbols lived forever. For example in Ruby 2.1:
One of the best features of the last 8th years, by far.
This has been one of te weakest points of Ruby for any interactive app, and clearly one of the most common weak point of any Rails app out there. (It has also been one of my favourite Ruby’s tales for new comers )
This “bug” has actually changed the respect we have towards Symbols, and even the way/place we use them, making us pick Strings in a lot of cases or at least forcing us to add dumb validations here and there.
Personally, I celebrate Symbol GC even more than named params or even some of the performance improvements.
JRuby mimicked MRI’s non-GCable Symbols in earlier versions, but JRuby 9000 – which will ship with Ruby 2.2 support – makes Symbols GCable just like MRI.
In JRuby, we do not use Symbols for IDs like method and constant names, so they will not cause an “immortal symbol” to be created.