Dear experts
I have a customized class that will been filled to a TTree
, I wonder do I need to call delete objectA; objectA = nullptr;
after every Fill()
?
Dear experts
I have a customized class that will been filled to a TTree
, I wonder do I need to call delete objectA; objectA = nullptr;
after every Fill()
?
Hi @Crisps!
No, you should not call delete
after every fill.
See the documentation (ROOT: TTree Class Reference):
The object must not be destroyed (i.e. be deleted) until the TTree is deleted or TTree::ResetBranchAddress is called.
You’re creating the object once on the beginning, like here in this tutorial:
https://root.cern/doc/master/tree4_8C.html
Here, the object is this:
// Create a pointer to an Event object
Event *event = new Event();
Note that this tutorial has a memory leak because event
is never deleted (according to the docs I linked before, it should be kept alive until the TTree is destructed).
I hope this helps!
Jonas