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.
>