Re: [ROOT] No AutoDelete ot TClonesArray in TreeViewer?

From: Rene Brun (Rene.Brun@cern.ch)
Date: Thu Oct 24 2002 - 22:39:55 MEST


Hi Daniel,

 - As indicated in a previous mail, I strongly suggest you move
to a PRO version like 3.03/09 or at least use a PRO version
such as 3.02/07.

 - You are confusing TObject::New with a call to your object constructor.
TObject::New is precisely doing the work that you suggest.

- if calling TClonesArray::Delete instead of Clear solves your leak
problem, this means that your Fragment class is allocating objects or
arrays dynamically. If you want to take advantage of the TClonesArray
you should avoid this as much as possible.
Note also that 3.03/09 takes care of this problem.

Rene Brun

On Thu, 24 Oct 2002, Daniel Cussol wrote:

> 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