What should happen here?
Ali Çehreli
acehreli at yahoo.com
Sun Sep 26 00:23:19 UTC 2021
On 9/25/21 3:19 PM, Walter Bright wrote:
> On 9/25/2021 10:46 AM, Steven Schveighoffer wrote:
>> Right, but the optimizer is working against that.
>>
>> For example:
>>
>> ```d
>> auto c = new C;
>> .... // a whole bunch of other code
>>
>> c.method; // not necessarily still live here.
>> ```
>>
>> Why would it not be live there? Because the method might be inlined,
>> and the compiler might determine at that point that none of the data
>> inside the method is needed, and therefore the object is no longer
>> needed.
>>
>> So technically, it's not live after the original allocation. But this
>> is really hard for a person to determine. Imagine having the GC
>> collect your object when the object is clearly "used" later?
>
> I understand your point. It's value is never used again, so there is no
> reason for the GC to hold on to it.
I must be misunderstanding Steven's example. You say "its value is never
used again" yet his example has
c.method
which to me is clearly "using" it again. So, I don't understand Steven's
"not necessarily still live here" comment either. Is the case today?
> After the point when the value is
> never used again, when the destructor is run is indeterminate.
I accept that part.
The to-me-new concept of non-lexical scoping scares me if the
non-lexical scope is shorter than lexical scope. And especially when the
value is clearly used by `c.method`. (If I heard non-lexical scoping, I
must have taken it as "destructor may be executed later than the lexical
scope".)
Ali
More information about the Digitalmars-d
mailing list