I have noticed some things about memory allocation while using ROOT and I’d like to know 1) if what I am seeing is typical behavior and 2) if there’s a way to limit how much memory ROOT uses.
I have a relatively simple Event class with member varialbes of the standard types and no arrays/TClonesArrays. I then make a simple program to open a TFile, a TTree, fill members of an instance of my Event class with some values, TTree::Fill(), and then write the file (standard event loop…). At first, it allocates about 20 MB and hums along fine. But after about one million events (1000000), the memory allocation quickly jumps up to 200 MB and then up to 600, 700 MB and more. I can reproduce this behavior on my system by using the modified versions of Event.cxx/.h and MainEvent.cxx (found in ROOTSYS/test) and running “./Event 2000000 1 99 1”. (In this modified code, its just filling the Event class without any Tracks and just setting one member variable.). On my system (root v5.26 and mac os 10.6), the program initially allocates ~17 MB, but after about 800000 events, that memory use goes up to hundreds of MB.
Is this normal behavior? I suspect that this memory allocation is causes by ROOT trying to compress this data and write it to disk, but the for-loop is quickly creating a large number of events and ROOT can’t keep up. Is this the case? And does ROOT know that my system has ~1 GB of free space in memory and that it can safely allocate that memory as it needs to quickly perform the compression?
Also, is there a way of limiting how much memory ROOT can use?
I started looking at this issue because I was trying to track down a memory leak. At least, I thought it was a memory leak, but I’m not so sure now.
Thanks for your help.