What should happen here?
Walter Bright
newshound2 at digitalmars.com
Sat Sep 25 02:19:55 UTC 2021
On 9/21/2021 3:58 AM, Johan wrote:
> First: the use of "stack" here is wrong and confusing. It should be "local
> storage" (notorious error throughout the spec). Indeed, what is done in your
> example is putting the pointer in local storage. The scope of that local storage
> is until the end of function scope (in your example). I don't think (in LDC)
> that we track the lifetime of variables in that way, so what is done is that the
> optimizer just looks at last point of use. This is similar to how Java behaves:
> https://stackoverflow.com/questions/39285108/can-java-garbage-collect-variables-before-end-of-scope
Data flow analyzers are not scope-based, they are based on first use and last
use. The @live pointer tracking does this, too. Destructors happen on going out
of scope, but the compiler can move them as long as the code behaves "as if" the
destructor happened at the end of scope.
But garbage collection, the class destructors are run at some arbitrary time
after last use, not after going out of scope.
More information about the Digitalmars-d
mailing list