Stack or heap? What's that?

Stewart Gordon smjg_1998 at yahoo.com
Tue Jan 16 04:42:12 PST 2007


Manfred Hansen wrote:
<snip>
> One question. What do the destructor ~this ?
> Delete he also the reference on the stack to the object
> in the heap ? 

No.

The destructor is automatically called when the GC detects that the 
object is no longer reachable, just before it releases the memory held 
by it.

If you trigger the destructor to run by a DeleteExpression, then

file:///e:/dmd/html/d/expression.html#DeleteExpression
"The pointer, dynamic array, or reference is set to null  after the 
delete is performed."

For example:

     class Qwert {}

     void main() {
         Qwert yuiop = new Qwert;
         delete yuiop;
         assert (yuiop is null);
     }

but this behaviour is part of DeleteExpression, not of the destructor.

Stewart.



More information about the Digitalmars-d mailing list