Re: [ROOT] question about Event class

From: Rene Brun (Rene.Brun@cern.ch)
Date: Sat Jul 12 2003 - 18:21:54 MEST


Hi Sebastien,

You get a memory leak because you never clear the TMatrixD dynamic
structure. To facilitate this task, I have implemented TMatrixD::Clear
in the CVS version.
See the new tar file in the attachement to see how I call this function.

Note that it is quite expensive to create dynamic objects inside a TClonesArray,
even it is fully supported by the recent versions.
In your case, if your covariance matrix is always the same size,
you have interest to insert a static 2-d array instead.

Rene Brun


Sebastien Greder wrote:
> 
> Hello Rooters,
> 
> I got some troubles by trying to change the Event class (in the ROOT test/
> dir.).
> 
> I just added a member to the class Track :
> 
> TMatrixD fCovariance;
> 
> so that the Track constructor is now :
> 
> Track::Track(Float_t random) : TObject() , fCovariance(5,5)
> 
> Since creating a TMatrixD allocates memory, I need to change
> the Event Clear() method by replacing the line :
> 
> fTracks->Clear("C); by :
> 
> fTracks->Delete() ;
> 
> otherwise I get a memory leak.
> 
> I then compile and run the exe Event : ./Event 1000 1 1 1
> 
> to create a Event.root file.
> 
> everything works fine until here.
> 
> If then I re-run the exe : ./Event 1000 1 1 0
> 
> just to read the Event.root file or if I execute
> I get a huge memory leak.
> By checking the file MainEvent.cxx, I see that
> in the reading mode (read ==1), there's no call
> to the Event Clear() method , is this correct ??
> I thought not and added this call, thinking it would
> reduce the memory leak, but on the contrary it's even
> worse (the effect is the same using the macro eventa.cxx which
> does the same stuff).
> 
> Could so tell me where I did something wrong ?
> 
> thanks,
> 
> seb.
> 
> I put a tar.gz file to reproduce the pb under :
> 
> /afs/in2p3.fr/home/g/greder/public/Event_pb.tar.gz
> 
> I'm running under RH 7.2, gcc 2.96, ROOT version 3.03.09
> (I'm checking if I get the same pb with 3.05.05)




This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:13 MET