Reading my tree causes a memory leak. I reproduced this problem in a small test program:
get this tar file:
~cbern/public/tree.tgz
tar -zxvf tree.tgz
cd Tree
make
./Debug 1
creates and fills the tree. It will be stored in test.root
./Debug 0
reads the tree. The printout of the object table shows that the number of TRefArrays is growing. This is the reason for the memory leak.
Now have a look at Debug.cc, reading stage.
As you can see, I’m adding a track to the event object at each event. Note however that the number of tracks is constant, as it should be. Tracks are correctly deleted, but not the TRefArray owned by the track.
I tried to force a call to my destructors by doing:
GetEntry will get the 100 tracks per event out of the tree.
then, I’m adding one track.
This is just a dummy example. My real tree is used for clustering purpose. The event contains an array of cells, an array of clusters made of cells and so on. The simulation program propagates the particles to the calorimeters, and produces a list of cells with an energy deposit, and does some clustering.
Cells and clusters are saved in the tree.
Then, out of the simulation program, I’m redoing the clustering, and add the new clusters to the event TClonesArray of clusters. This allows to treat old and new clusters in the same way, eg. for display.
All clusters (old and new ones) contain a TRefArray to cells, which is not deleted before reading a new event, whereas the clusters seem to be deleted correctly. Hence the memory leak.
Thanks a lot, it works for the test program, and I could cure part of the leak in the real one. I still have a small leak, which is under investigation.