Hello rooters, I am a little bit puzzled by the TClonesArray. I have designed an Event class wich contains a TClonesArray of Fragment class (derived from TObject). Fragment instances are created in the contructor of the Event class. I have set to kTRUE the AutoDelete for the branch of the TTree which contains the event. When I want to read the TTree with the TTreeViewer, a huge amount of Fragment instances is created. This means that the Fragments in the TClonesArray are always created and never deleted which leads to a memory leak. I tried many things to avoid this behaviour but I did not manage to fix it. If I use the TTree::Process method to read and analyse the TTree, all is ok providing I call the TClonesArray::Delete() method before reading a new entry. If I call the TClonesArray::Clear() instead, I have a memory leak. I thought naively that if the objects in the TClonesArray were existing, there was no need to create some more. It is obviously not the case! When looking at the source code of the TClonesArray, I have noticed that a call to the TObject::New() method is always done while reading the TClonesArray. Is it necessary if the object already exists in the heap? Not creating objects when they already exist in the TClonesArray could gain time and memory. Is my understanding of the TClonesArray class correct? If not, is there a way to avoid the behaviour mentioned above? I use ROOT v3.02/04 on Unix Compaq DS20 machine (alphacxx6). Thanks for your answers. Friendly Daniel CUSSOL LPC Caen Boulevard du Marechal Juin 14050 CAEN CEDEX e-mail : cussol@in2p3.fr Tel : +33-(0)2-31-45-29-73 FAX : +33-(0)2-31-45-25-49
This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:15 MET