Why does D rely on a GC?

Dicebot via Digitalmars-d digitalmars-d at puremagic.com
Mon Aug 18 05:49:48 PDT 2014


On Monday, 18 August 2014 at 12:27:44 UTC, Maik Klein wrote:
> Is it correct that when I create a class it will always be on 
> the heap and therefore be garbage collected?
>
> class Foo
> ..
>
> So I don't have the option to put a class on the stack like in 
> C++?
>
> auto foo = Foo(); //stack
> auto foo_ptr = new Foo(); // heap
>
> If I do something like:
>
> auto ptr = Unique(Foo);
>
> Would the GC still be used, or would the resource be freed by 
> the destructor?

http://dlang.org/phobos/std_typecons.html#.scoped


More information about the Digitalmars-d mailing list