November 03, 2007 Full closures - Variable needlessly allocated on heap | ||||
---|---|---|---|---|
| ||||
Compiled using DMD 2.007 on Windows. int delegate() foo(){ int a = 30; int b = 60; int c = 90; int one(){ return a; } int two(){ return b; } writefln(&a); writefln(&b); writefln(&c); return &one; } version(Windows) void main(){ foo(); } Prints: 8B2FF4 8B2FF8 12FF28 This means that variable 'b' is being allocated on the heap, even though nested function 'two' is never referenced. |
Copyright © 1999-2021 by the D Language Foundation