Lazy and GC Allocations

Etienne etcimon at gmail.com
Mon Feb 20 21:25:55 UTC 2023


On Monday, 20 February 2023 at 19:58:32 UTC, Steven Schveighoffer 
wrote:
> On 2/20/23 1:50 PM, Etienne wrote:
>> On Monday, 20 February 2023 at 02:50:20 UTC, Steven 
>> Schveighoffer wrote:
>>> See Adam's bug report: 
>>> https://issues.dlang.org/show_bug.cgi?id=23627
>>>
>> 
>> So, according to this bug report, the implementation is 
>> allocating a closure on the GC even though the spec says it 
>> shouldn't?
>
> The opposite, the delegate doesn't force a closure, and so when 
> the variable goes out of scope, memory corruption ensues.
>
>> I've been writing some betterC and the lazy parameter was 
>> prohibited because it allocates on the GC, so I'm wondering 
>> what the situation is currently
>
> It shouldn't. Now, lazy can't be `@nogc` (because that's just 
> what the compiler dictates), but it won't actually *use* the GC 
> if you don't allocate in the function call.
>
> I just tested and you can use lazy parameters with betterC.
>
> -Steve

The @nogc issue might be what might be why it didn't work for me. 
I use it because it's easier to work with betterC but perhaps I 
should avoid writing @nogc code altogether

Thanks for the info!

Etienne



More information about the Digitalmars-d-learn mailing list