gc heap

Jarrett Billingsley jarrett.billingsley at gmail.com
Sun Nov 23 14:22:18 PST 2008


On Sun, Nov 23, 2008 at 5:02 PM, Sam S E <asdf at mailinator.com> wrote:
> What is allocated in the gc heap? Just classes? Dynamic/associative arrays? Structs? Only things allocated with new? Do built-in types and structs get deallocated at the end of scope like in C?
>

Everything that is a reference type (classes, dynamic arrays, AAs) is
allocated on the heap.

Everything that is a value type (basic types, fixed-size arrays,
structs) are allocated on the stack and are deallocated when the scope
is left.

scope references to classes will delete the class they refer to when
the scope is left.  As a special case, a declaration of the form
"scope x = new ClassType()" will actually allocate the class instance
on the stack instead of on the heap.


More information about the Digitalmars-d-learn mailing list