Ruby symbols are not garbage collected!? Then, isn't it better to use a String?
问题 If you create 10,000 strings in a loop, a lot of garbage collection has to take place which uses up a lot of resources. If you do the same thing with symbols, you create objects which cannot be garbage collected. Which is worse? 回答1: If you refer to the same symbol in your loop, then it doesn't have to recreate that object everytime i.e. while i < 10000 i += 1 :im_using_this_symbol_here end Now if you use a string there instead, the string will be recreated 10K times. In general, use symbols