On Thursday, 27 May 2021 at 18:13:17 UTC, Adam D. Ruppe wrote:

If the delegate is created by the GC and stored it will still be managed by the GC, along with its captured vars.

As long as the GC can see the delegate in your example you should be OK. But if it is held on to by a C or OS lib, the GC might not see it and you'd have to addRoot or something to ensure it stays in.

With lambdas in C++ you can cherrypick captures the way you want, then somehow this can be converted to an std::function and this is where it goes on the heap as well.

In D, how does the compiler know what captures it is supposed to store, or does it take the whole lot?

Reply via email to