Handling referencing class parent instances in a GC friendly way.

realhet real_het at hotmail.com
Mon Nov 30 14:33:22 UTC 2020


Hi,

class A{
   A parent;
   A[] items;

   void myDestroy(){
     items.each!(i => i.myDestroy);
     parent = null;
     // after this point I think the GC will release it 
automatically, and it will call ~this() too. Am I right?
   }
}

I have a hierarchy of class instances forward and backward linked 
to its items ant its parent.

What is a proper way to destroy an instance of class A? Is 
calling instance.myDestroy sufficient?

Am I right that this kind of uninitialization MUST not go into 
the ~this() destructor, because of the references the instance is 
holding, the system will never call the ~this()?

Or is there a better way for this type of thing in Dlang?


Thanks in advance!


More information about the Digitalmars-d-learn mailing list