Home | News | Documentation | Download

Deleting a TTree and checking

tree
ttree

#1

Hi,

I am using ROOT 6.09.01 to plot data from a text file on my cluster. I am using the following code:

TTree *MyTree = new TTree(“MyTree”,“MyTree”);
MyTree->ReadFile(“TextFile.txt”,“X:Y”);
MyTree->Draw(“X:Y”,"","");

However, I do not know the proper way to delete “MyTree” or check if it was deleted.

is
delete MyTree;

the proper way or,

MyTree->Delete();

and how do I check to see if it has been deleted?

Thanks,
Alejandro


#2
delete MyTree; MyTree = 0;

#3

Ok, but how can I check to see if I deallocated the memory? Also wouldn’t typing MyTree =0; after delete MyTree; be pointless? It just looks like I’m defining a variable after I deleted MyTree.


#4

Adding MyTree = 0; is just an additional (surplus?) protection. Just to make sure that if you (accidentally?) use the “MyTree” after it’s been deleted, you should get null pointer there (and then hopefully a clear error message).


#5

OK, Thanks for the clarification!


#6

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.