Destructor called while object is still alive

Johan Engelen j at j.nl
Fri Oct 23 23:30:20 UTC 2020


On Friday, 23 October 2020 at 20:27:37 UTC, frame wrote:
>
> Even if I do not run into memory problems, calling the 
> destructor on a live object is an unepxected side effect which 
> makes the dtor concept useless for me. It closes the remote 
> connection the object hold (please don't ask about the meaning, 
> it just the way it has to work) and this must not happen while 
> the program is still running.

Hi frame,
   Regardless of the topic being discussed, you should not do 
resource management using ctor/dtor of a GC-managed object. The 
dtor is not guaranteed to be called (not even on program exit). 
Indeed, the dtor as you know from stack allocated objects works 
very differently for GC-allocated objects; this feels like the 
dtor concept is useless (I agree, I've also grown used to 
RAII-thinking about dtors).

cheers,
   Johan



More information about the Digitalmars-d mailing list