Deleting a TTree and checking


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”);

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

delete MyTree;

the proper way or,


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


delete MyTree; MyTree = 0;

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.

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

OK, Thanks for the clarification!

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