Delegate is left with a destroyed stack object
Peter Alexander
peter.alexander.au at gmail.com
Tue Oct 29 14:32:38 PDT 2013
On Tuesday, 29 October 2013 at 21:14:39 UTC, qznc wrote:
> Returning closures with reference to stack memory is a bad
> idea. Maybe @safe should prohibit this?
According to http://dlang.org/function.html
"The stack variables referenced by a nested function are still
valid even after the function exits (this is different from D
1.0). This is called a closure."
It it completely valid to reference that memory. It gets moved
onto the heap when you create the closure. The problem is that
the destructor still gets called, so the variable is no longer in
a valid state post return.
More information about the Digitalmars-d
mailing list