Garbage collection and closures.
ANtlord via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Jun 17 07:19:34 PDT 2017
On Saturday, 17 June 2017 at 13:13:17 UTC, Adam D. Ruppe wrote:
> On Saturday, 17 June 2017 at 13:03:28 UTC, ANtlord wrote:
>> Is GC called every iteration of this loop?
>
> No, it will once on scope entry; where the deepest-referenced
> variable that is actually captured is defined. The compiler
> allocates heap space instead of stack space for the locals,
> then runs the function normally using that space.
Excuse me, I can't get what does it mean "deepest-referenced".
What the deep you mean? The deep of a closure or deep of the
function where the variable is defined. Can you give an example
code?
> It will only alloc once. You can prove this with a debugger
> btw, set a breakpoint on `_d_allocmemory`.
Is this function called every time when allocation happens in a
heap?
Thank you. Sorry if my English is not clear.
More information about the Digitalmars-d-learn
mailing list