This is what I mean:
class mycalss { string myfunc() { string str='hello'; return str; } } ... static void main() { string str2; str2=myfunc(); ... ... }
In this case is there a risk that the garbage collector might delete the contents of str2 because str went out of scope?
No. The garbage detector will see that str2 has a reference to the data, and it won’t be collected.