When is a class's destructor called?

Mike none at none.com
Sat Dec 28 22:57:58 PST 2013


On Sunday, 29 December 2013 at 06:53:08 UTC, Mike Parker wrote:
> On 12/29/2013 2:03 PM, Mike wrote:
>
>>
>> x's destructor never gets called.  What do I need to implement 
>> to have
>> the destructor called when x goes out of scope?
>>
>
> Class destructors are not called when an object goes out of 
> scope. They are called by the garbage collector only when 
> memory needs to be reclaimed or during the cleanup cycle during 
> app shutdown.

Ok, I understand that, but since I don't have a garbage 
collector, what must I implement to call the destructor when it 
goes out of scope?

Another way of asking the question is: How does the garbage 
collector know when something has gone out of scope and is 
therefore safe to collect?  And where is that implemented in the 
runtime?



More information about the Digitalmars-d-learn mailing list