The following code apparently heap-allocates a closure even though doNothing() takes a scope delegate. This happens when doNothing() is passed a delegate literal. When it's passed the address of a named inner function, no heap allocation takes place. import core.memory; void main() { GC.disable(); foreach(j; 0..1_000_000_000) { doIt(); } } void doIt() { int i; doNothing(() { i++; }); } void doNothing(scope void delegate() dg) { dg(); }
https://github.com/D-Programming-Language/dmd/pull/598
https://github.com/D-Programming-Language/dmd/commit/f19992a6ac4dde4d16db61104bebc9303173518d https://github.com/D-Programming-Language/dmd/commit/21ce18fbc1241d4fbe06c2d78dd2114c4924b35a