TClonesArray::Delete() doesn't free objects' memory

Good afternoon. I’m working at NICA project in Joint Institute of Nuclear Research.
Our experiment software is based on FairRoot. One event is using a set of TClonesArray objects allocating about 2GB memory, that is why clearing memory is very important before next event. We are using TClonesArray::Delete() method before next run, but it doesn’t free memory.
I believe it happens because of TObject::SetDtorOnly(fCont[i]) flag (before delete fCont[i]) in TClonesArray::Delete() method (//Only destructors are called for this object). TClonesArray::Clear() also doesn’t free memory. How can I free memory of objects contained in TClonesArray.

P.S. TObjArray::Delete(Option_t *) method free objects’ space (fCont[i]), but FairRoot’s Register() method is oriented on TClonesArray.

With best wishes, Konstantin.

We need more information from your side. In particular, we have to know if the objects in the TClonesArray in turn allocate new objects or dynamic structures.
Could you come with a simple and short demonstration case showing what you are doing?

Rene

For example, reconstruction event uses TClonesArray with 5 million “PrimaryCluster” objects. “PrimaryCluster” class has 8 simple members (double precision). 350 MB of operative memory is allocated for this TClonesArray.
But when I try to free space after use (350 MB - 5 million * sizeof(pointer) = 350 - 40 = 310 MB) by TClonesArray::Delete(), memory isn’t cleared. However, memory overheads won’t grow up for this TClonesArray next event. How can I free this 310 MB.

So, it’s impossible to free memory allocated for objects of TClonesArray (by Delete() or Clear() method) except “delete pMyClonesArray”, isn’t it?

Yes, the basic advantage of a TClonesArray is to reserve space for N objects and reuse this space again and again without allocation memory and deleting memory.
If you want to remove the space allocated by the TClonesArray, just delete the TClonesArray.

Rene

Thank yuo for answer.
Give me please one more explanation. Will Compress() method (called after Delete()) free memory allocated for objects of TClonesArray?

No TClonesArray::Compress eliminates only the null pointers and keeps the existing storage.
In Your case, you should use Compress followed by Expand(newsize).

Rene

Hi,

sorry to interfere :slight_smile: but I’d like to make sure that you know what you’re asking for, Konstantin: by freeing TClonesArray’s storage between events you are destroying the advantage of TClonesArray over e.g. std::vectors. Even if FairROOT is the reason for you to use TClonesArrays you might want to try to save its benefits, and not free its storage for each event. If one event uses 2GB of memory - what will the next event do? Also use approx 2GB? Then please re-use the TClonesArray storage by using the TClonesArray properly, it will save you a lot of CPU time. If you don’t know what I mean then let us know!

Cheers, Axel.

Thank you very much, Rene. All methods are clear for me now.

[quote=“Axel”]Hi,
sorry to interfere :slight_smile: but I’d like to make sure that you know what you’re asking for, Konstantin: by freeing TClonesArray’s storage between events you are destroying the advantage of TClonesArray over e.g. std::vectors. Even if FairROOT is the reason for you to use TClonesArrays you might want to try to save its benefits, and not free its storage for each event. If one event uses 2GB of memory - what will the next event do? Also use approx 2GB? Then please re-use the TClonesArray storage by using the TClonesArray properly, it will save you a lot of CPU time. If you don’t know what I mean then let us know!
Cheers, Axel.[/quote]

Thank you, Axel. I know what you mean and understand it. There are many TClonesArray objects allocating about 3 GB operative memory that is why I’m considering all the possibilities to decrease the overheads. it’s very interesting to know how many CPU time would I lost without the TClonesArray memory storage?