Symbols are never garbage collected in Ruby. 

http://stackoverflow.com/questions/659755/ruby-symbols-are-not-garbage-collected-then-isnt-it-better-to-use-a-string
 

-- 
Richard Schneeman
http://heroku.com

@schneems (http://twitter.com/schneems)




On Wednesday, September 12, 2012 at 11:00 AM, Gary Weaver wrote:

> Something that would work instead of a StringPool that is Ruby-ish is use of 
> symbols. Symbols are Ruby's answer to the StringPool. If things are stored as 
> symbols, you can work with them similarly as to what you would expect and 
> reduce # objects, e.g.
> 
> jruby-1.7.0.preview2 :008 > :error.object_id
>  => 2050 
> jruby-1.7.0.preview2 :009 > :error.object_id
>  => 2050 
> jruby-1.7.0.preview2 :010 > :error.to_s.chomp!('or').to_sym
>  => :err 
> jruby-1.7.0.preview2 :011 > :error.to_s.chomp!('or').to_sym.object_id
>  => 2052 
> jruby-1.7.0.preview2 :012 > :error.to_s.chomp!('or').to_sym.object_id
>  => 2052
> 
> So basically if everywhere in Rails documentation that referred to strings 
> instead specified constants, and if the method didn't support constants that 
> would be a good goal:
> http://guides.rubyonrails.org
> 
> But still, whenever you output a string to a log, it becomes a string. So, 
> you might be able to make some inroads by changes to Rails and related 
> documentation, but if Ruby "fixed it" instead via something like StringPool 
> (again- a major and breaking change), then you wouldn't have to worry about 
> wasting all that time on the Rails side.
> 
> In addition, many text editors and IDEs have different colors for Strings, so 
> that keys and values stand out better in examples like:
> 
> class Employee < ActiveRecord::Base
>   has_many :subordinates, :class_name => "Employee",
>     :foreign_key => "manager_id"
>   belongs_to :manager, :class_name => "Employee"
> end
> 
> So, if you switch to all symbols, it is a little more monotone, colorwise. 
> However, if you switch to Ruby 1.9 key/value then you could color the key in 
> a: :b differently by the fact that it ends in a colon vs. starting with one. 
> Unfortunately, the existing default color schemes don't usually do that.
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ruby on Rails: Core" group.
> To view this discussion on the web visit 
> https://groups.google.com/d/msg/rubyonrails-core/-/W-QsFXyc4cwJ.
> To post to this group, send email to rubyonrails-core@googlegroups.com 
> (mailto:rubyonrails-core@googlegroups.com).
> To unsubscribe from this group, send email to 
> rubyonrails-core+unsubscr...@googlegroups.com 
> (mailto:rubyonrails-core+unsubscr...@googlegroups.com).
> For more options, visit this group at 
> http://groups.google.com/group/rubyonrails-core?hl=en.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to rubyonrails-core@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-core+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en.

Reply via email to