Destruction in D

Idan Arye via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Apr 30 19:35:50 PDT 2015


On Thursday, 30 April 2015 at 23:27:49 UTC, bitwise wrote:
> Well, the third thing was just my reasoning for asking in the 
> first place. I need to be able to acquire/release shared 
> resources reliably, like an OpenGL texture, for example.

If you want to release resources, you are going to have to call 
some functions that do that for you, so you can't escape that 
"special stack frame"(what's so special about it?) - though the 
compiler might inline it.

When you use a GC the compiler don't need to invoke the 
destructor in the end of the scope because the object is 
destroyed in the background, but that also means you can't rely 
on it to release your resources, so languages like Java and C# 
use try-with-resources and using statements(corresponding) to 
call something at the end of the scope and end up using that 
stack frame anyways.


More information about the Digitalmars-d-learn mailing list