new TFile *f; new TTree *t; ... delete t; delete f;

From: Pasha Murat (murat@cdfsga.fnal.gov)
Date: Mon Apr 27 1998 - 20:56:14 MEST


	Alexander: 

you create your tree after opening the file in which case ROOT associates 
it with this file. When you close the file, file destructor also deletes 
your tree object. So you don't have to delete it twice. 

As far as I remember this issue has been discussed a couple of times already,
may be we add it to ROOT Howto's ? Or we need a special section for "hints"?

					pasha.
--------------------------------------------------------------------------------
Alexander Zvyagin writes:
 >                                            IHEP, Protvino, Russia, 27-APR-1998
 > 
 > Dear friends!
 > 
 > I have the following code:
 > 
 > {
 >   // Example 1
 > 
 >   TFile *root_file = new TFile("a.root","RECREATE", "file",9);
 >   TTree *tree      = new TTree("tree","tree");
 > 
 >   root_file->Write();
 >   root_file->Map();
 >   root_file->Print();
 >   root_file->Close();    // Close root file.
 > 
 >   delete tree;           // here!
 >   delete root_file;
 > }
 > 
 > produces next output:
 > 
 > TFile Writing Name=a.root Title=file
 > 980427/160834  At:64        N=86        TFile         
 > 980427/160835  At:150       N=104       TTree          CX =  2.71
 > 980427/160835  At:254       N=90        TFile         
 > 980427/160835  At:344       N=54        TFile         
 > TFile: name=a.root, title=file, option=CREATE
 > ******************************************************************************
 > *Tree    :tree      : tree                                                   *
 > *Entries :        0 : Total  Size =       104 bytes  File  Size =        104 *
 > *        :          : Tree compression factor =   1.00                       *
 > ******************************************************************************
 > 
 >  *** Break *** segmentation violation
 > 
 > 
 > Why "segmenation violation"?
 > 
 > If I remove  string  "delete tree;" the message
 > "*** Break *** segmentation violation" disappears.
 > 



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