What I find is this, optimization changes the whole story here.
01 uses Ansi Assign of the string on the return which copies over the contents of the class data string.
02 and up looks like it is making a reference to the string?
Not sure what you mean....
should just increment the refcount (unless somedata is an expression with operators....)
Just wildly guessed "UniqueString(result)"?
For the "move" code, be aware, that "result" for a function returning a string, is a "var param" => so you get passed in the variable to which the caller assigns (or sometimes a temp var as in between).
SetLength does make it unique though.
However, that should not make a difference. (Unless maybe if you do pchar access to the string)