From: ts Date: 2008-05-06T01:07:09+09:00 Subject: Re: String copy-on-write question Lars Christensen wrote: Well, it's best if you look at rb_str_substr() in string.c > str[100..-1] # this costs only a small amount of memory ruby just need to adjust the pointer and the length in the new object > str[100..-2] # this costs around 16MiB bytes of memory one character is missing from the previous string, if it do the same thing than previously then it must * adjust the pointer * adjust the length * add \0 at the end This mean that fatally it has modified the string, this is why it duplicate. > p $'.size # This is free > p $`.size # This costs another 8MiB. same reason here. Guy Decoux