Re: [ROOT] Do I have to call the d'tor?

From: Rene Brun (Rene.Brun@cern.ch)
Date: Thu Nov 01 2001 - 12:10:17 MET


Hi Thomas,

Thomas Bretz wrote:
> 
> Hello rooters,
> 
> I'm not sure about the follwing:
> 
> ---
> TClonesArray c* = new TClonesArray("MyClass", 100);
> for (int i=0; i<100; i++) new ((*c)[i]) MyClass;
> [...]
> delete d;
> 
> Do I have to call this, too?
> for (int i=0; i<100; i++) delete (*c)[i];
> ---
> 

No, this will be done automatically by the TClonesArray destructor.
Note that if your class redefines the delete operator (unlikely),
The TClonesArray constructor says:
   // Create an array of clone objects of classname. The class must inherit from
   // TObject. If the class defines an own operator delete(), make sure that
   // it looks like this:
   //
   //    void MyClass::operator delete(void *vp)
   //    {
   //       if ((Long_t) vp != TObject::GetDtorOnly())
   //          ::operator delete(vp);       // delete space
   //       else
   //          TObject::SetDtorOnly(0);
   //    }
   //


> And something different:
> ---
> TFile *file = new TFile(...);       // open a file
> TTree *tree = new TTree(...);       // create a tree
> TBranch *branch=tree->Branch(...);  // create a branch
> [...]
> file->Write();
> delete file;   // close the file
> 
> Do I have to call also:
> delete tree;
> delete branch;
> ----
> 

No, you do not have to delete tree and branch.
The branch is automatically deleted by the Tree destructor.
The Tree is automatically deleted by the TFile destructor unless you have
called tree.SetDirectory(0);

Rene Brun

> Thanks a lot,
> Thomas.



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:51:05 MET