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

Alexander Zvyagin (zvyagin@mx.ihep.su)
Mon, 27 Apr 1998 22:14:31 GMT+03:00


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.

The following code works well:

{
// Example 2

TFile root_file("a.root","RECREATE", "file",9);
TTree tree("tree","tree");

root_file->Write();
root_file->Map();
root_file->Print();
root_file->Close(); // Close root file.
}

Why code 'Example 1' with new-delete operators is bad?

Thanks in advanced,
Alexander Zvyagin.