On Wednesday, 2 April 2014 at 15:53:52 UTC, Jacob Carlborg wrote:
On 2014-04-02 17:45, Andrea Fontana wrote:
auto example(char* test) { return toStringz(to!string(test) ~
" world!"); }
When that return string will be freed?
When there is no reference left to the string, the garbage
collector is free to collect it when it chooses to.
That's expected.
What about:
extern(C) auto example(....)
Same as above, extern(C) does not change how memory is
collected. If it is a C function, then it depends entirely on
that particular function.
I mean: if it is an exported function (of a shared library) what
happens? There's no reference kept anywhere (in D). So if I'm
right it could be freed immediatly by GC. Right?