Reading root-file causes memory leak

Hello rooters!

In our experiment, our root-files (filled with histograms) are created by a MIDAS-based analyzer. A typical root-file is found in the attachment.
If I let run the attached script, which reads in the same histo from the opened file a number of times, a memory leak of 70 MB per iteration (sums up to 3.5 GB! for iter=50) is produced.

Can anybody please tell me what is wrong here?

Taking the same code and reading in the histo “hpx” from hsimple.root does not produce a significant memory leak.
Letting the code run on “myhsimple.root”, which contains only one histo inside a TFolder, results in a minor memory leak of around 7kB per iteration.

Your help is greatly appreciated!!!

Tobias Nebel

(my apologies for the large attachment…)
myhsimple.root (379 KB)
mem_leak_1.cxx (2.24 KB)
a10999_c.root (1.94 MB)

If you disable the default ROOT ownership, it is up to you to delete the objects that you import from the file. You should set your folders owners of the objects inside such that they will be automatically deleted when deleting the top level folder. In this case I recommend
to set the ownership when creating the folder.
In your case you can set the ownership as illustrated in your slightly modified program in the attachment. (see lines with //<================)
Note that your use of folders is quite expensive as you have to import a very large collection of histograms every time you want to use only one of them. It would be less expansive to create directories in the file directly.

mem_leak_1.cxx (2.6 KB)