I'm not deleting somthing and I don't know what

here is my code which i need to repeat many times in my application.

TFile *f = new TFile(“data/KinematicsAll.root”,“UPDATE”);

TChain *chain = new TChain(“Event0/TreeK”);
chain->Add(“Kinematics.root”);
TTree newtree = (TTree)chain->CloneTree();

Char_t evName[100];
sprintf(evName,“Event%d”,curEvK);
f->mkdir(evName);
f->cd(evName);
newtree->Write();
delete chain;
delete newtree;
f->Close();

Hi,
this is what your code look should look like:

[code] TFile *f = new TFile(“data/KinematicsAll.root”,“UPDATE”);

TChain *chain = new TChain(“Event0/TreeK”);
chain->Add(“Kinematics.root”);

Char_t evName[100];
sprintf(evName,“Event%d”,curEvK);
f->mkdir(evName);
f->cd(evName);
TTree newtree = (TTree)chain->CloneTree();
newtree->Write();
delete f;
delete newtree;
delete chain;[/code]

Cheers, Axel.

delete newtree; (cause the Segmentation fault)
i remove it, but after that i see that my memory is increasing (probably not deleting everything)

delete f; delete newtree;The TTree read and wrote to a TFIle belong to the TTree object and hence are deleted when you delete the file (and thus the above code lead to a double delete).

[quote]i remove it, but after that i see that my memory is increasing (probably not deleting everything)[/quote]PLease use valgrind (valgrind.kde.org) to track those leak down.

Cheers,
Philippe.

the problem with the memory that i can’t delete is after this command

what can i do?

Or is there any way how to copy the tree from one root file to another root file, but i wanna put this tree to another directory in the new root file.

for example: from f1.root (EventX/TREE) to f2.root (EventY/TREE)

thanks

[quote]the problem with the memory that i can’t delete is after this command
Code:
TTree newtree = (TTree)chain->CloneTree();[/quote]
You do not need to delete it. It is owned by the TFile object.
Philippe

[quote=“pcanal”][quote]the problem with the memory that i can’t delete is after this command
Code:
TTree newtree = (TTree)chain->CloneTree();[/quote]
You do not need to delete it. It is owned by the TFile object.
Philippe[/quote]
when i close the file memory (RAM) is not free-ing

[quote]when i close the file memory (RAM) is not free-ing[/quote]From your descriptions, I do not see why this is the case nor how you assert this fact. I recommend that you try valgrind (valgrind.kde.org) to narrow down the source of the leak (if any).

Cheers,
Philippe.

PS. Alternatively, provide a complete running example showing your problem as well as what you see/observe when running it and what is different from your expectation.