On Wednesday, September 12, 2012 11:06:43 AM UTC-4, richard schneeman wrote:
>
> Symbols are never garbage collected in Ruby.
>

Good point. However, for Rails, I'd think you'd still use less memory if 
symbols were just used for class, controller, model, field names in views, 
etc.

Even if Rails had to do handfuls (or 100s) of symbol -> string -> some 
change to string -> to_sym'ing during startup, the memory consumption would 
very likely be less than not doing it.

You wouldn't want to store every value retrieved from a database as a 
symbol obviously, nor store all values in incoming request params as 
symbols, and if things in Rails are doing regexp's on something, it 
wouldn't make sense to constantly be to_s'ing (in one way or another) to 
operate on them.

There is a balance between needing to garbage collect and needing to keep 
too many objects from being instantiated, even if they are GC'd. But you 
are right- the Java StringPool would GC something that was no long 
referenced, I believe, and if symbols are used for large varying strings, 
that's a memory leak, but that's not what I'm talking about.

-- 
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/-/hIkusaGHkUsJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en.

Reply via email to