Re: Histograms in gDirectory.

From: Pasha Murat (murat@cdfsga.fnal.gov)
Date: Thu Jul 09 1998 - 20:24:22 MEST


Alexander Yuryevich Zvyagin writes:
 > Dear ROOTers,
 > 
 > I'd like to discuss one feature of the TH1 class: how the member function
 > void TH1::Build() works. (You'll find the function body at the end of this
 > E-mail.) This function is called when TH1 constructor is invoked.
 > 
 > // Example 1.
 > TH1F a("E",....), b("E",....);
 > 
 > This is *good* C++ code and this is *bad* ROOT code.
 > What will ROOT do?
 > The histogram a("E",...) is created and added
 > (See TObject::AppendDirectory()) to the current directory. On default it
 > is gDirectory. OK, you have histogram 'a'. Then ROOT will try to create
 > histogram b("E",...) with the *same* name "E" as the histogram 'a' has.
 > ROOT will find that object with the same name already exists in the
 > gDirectory and it'll try to *delete* it. 

	this is half-true: in this case  ROOT will delete `a' from the list 
	of existing histograms but not necessarily it will e trying to delete 
	the object itself.
 >
 >                                            So ROOT will delete pointer to
 > statically allocated object. Something like this:
 > {
 >   int a;
 >   int *b = &a;
 >   delete b;
 > }
 > This is bad thing. Your *good* C++ code will crash. I think this is
 > ROOT bug.

	Yes, this is a bad thing to do so as far as I understand (please 
	correct me if I'm wrong here) ROOT doesn't do it: 
	TObjects in ROOT containers "know" if they were allocated statically 
	or on the heap. Any TSequence(TList, TObjArray etc)::Delete method 
	deletes only those allocated on the heap.

						Regards, pasha.



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:34 MET