I'm working on a project that looks like it'll need manual memory management (the end goal is to get it running on ARM using GDC, where the GC doesn't seem to behave (that goal might be unrealistic, but I can hope)), and I'm trying to figure out how to deal with closures. My understanding is that a closure is a function pointer and the enclosing scope, whether that scope is variables that are copied into the closure or a class instance to use as "this." Is this correct?<div>

<br></div><div>Assuming that's correct, this would involve a memory allocation, right?</div><div>----------</div><div>class Test {</div><div>void doStuff() {}</div><div>}</div><div><br></div><div>void doSomethingElse(void delegate() thing) {</div>

<div>thing();</div><div>}</div><div><br></div><div>void main() {</div><div>auto test = new Test();</div><div>doSomethingElse(&test.doStuff);</div><div>}</div><div>----------</div><div><br></div><div>My understanding is that as soon as I run "&test.doStuff" a closure is generated. Is this correct? Would it then be valid, in doSomethingElse, to run "GC.free(thing)" ?</div>

<div><br></div><div>Any insight would be appreciated.</div>