From: Robert Dober Date: 2009-01-23T09:39:25+09:00 Subject: Re: String doesnt auto dup on modification On Wed, Jan 21, 2009 at 8:15 PM, RK Sentinel wrote: > I'm writing my first largeish app. One issue that gets me frequently is > this: > > I define a string in one class. Some other class references it, and > modifies it. I (somehow) expected that when another referer modifies the > reference, ruby would automatically dup() the string. > > Anyway, through trial and error, I start dup()'ing strings myself. I am > aware of freeze(). > > But would like to know how others handle this generally in large apps. > > - Do you keep freezing Strings you make in your classes to avoid > accidental change > > - Do you habitually dup() your string ? I try to, and I try to get rid of all references to the original string as soon as possible. This is because incremental GC works so well nowadays and allows for some clean code. Freezing a string seems like a good idea sometimes, but if that means holding on to the object longer than needed this might not be such a good idea after all. R. -- It is change, continuing change, inevitable change, that is the dominant factor in society today. No sensible decision can be made any longer without taking into account not only the world as it is, but the world as it will be ... ~ Isaac Asimov