How long does the context of a delegate exist?
cc
cc at nevernet.com
Sun May 30 09:39:28 UTC 2021
On Thursday, 27 May 2021 at 20:46:22 UTC, Adam D. Ruppe wrote:
> On Thursday, 27 May 2021 at 20:44:21 UTC, frame wrote:
>> Did you mean to add the delegate as GC root or the data?
>
> The delegate.ptr property.
Is there any way to enforce at compile time that we're not
accidentally allocating when creating a delegate, other than
being carefully aware of what variables are referenced inside the
body? Something like:
```d
auto dg = delegate {...}
assert(dg.ptr is null, "Oops, we unintentionally allocated on GC
here, check delegate body!"); // can't static assert
```
More information about the Digitalmars-d-learn
mailing list