Re: [ROOT] When I Clone an object that inherits from TObject, do I need to delete it at the end?

From: Rene Brun (Rene.Brun@cern.ch)
Date: Thu Nov 01 2001 - 08:42:16 MET


Hi Isi,

When Cloning an object, you create a new instance of the class. Internally,
Clone calls the new operator (via the compiler or the interpreter).
You must do the bookeeping of this cloned object like if you had called new.

Rene Brun

Isard_Dunietz wrote:
> 
> //If I have a
> TH1F * hist;
> //And I wish to clone it such as
> TH1F const * clonedHist = static_cast< TH1F *> (hist->Clone("clonedHist"
> ));
> // Once the job of clonedHist is done does one need to delete it
> delete clonedHist;
> // or not?
> 
> //
> // I.e, is clonedHist a ptr to a new TH1F(/*  */),
> // in which case I must delete it when done with it, or
> // there is no newing involved in which case I must not delete clonedHist;
> // at the end?
> 
> // Maybe this is not relevant when I write a macro or a fnct and am using
> cint
> // (but I still would want to
> // consistently delete what was newed).
> 
> // Is'nt this point important to
> // know when I write my own main() and load all the necessary root headers
> into
> // my main program.
> 
> // Is there a difference when I use my own main() and when I use cint?
> 
> I tried to follow the chain of TH1::Clone -> TNamed -> TObject but I was
> not able to see through what a G__ClassInfo * actually is so I could not
> push throughthe complete reasoning.
> 
>           Thank you, your confused Isi



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