Avoiding GC of objects within loop

Hi all

Having a list of strings that represent file names, I wanted to loop over the filename list, open the files, get the tree from each file and append it to a “tree storage” list, so something like

filenames = ["file1.root" , "file2.root", "file3.root"]
treename = "treename"
treeslist = []

for infile in filenames:
	tmp_tree = ROOT.TFile.Open(infile, "read").Get(treename)

This results in something like

I tried setting the ownership, tmp_tree.Reset(), and also creating a new tree and cloning the old using something lile:

newTree = ROOT.TTree("atree","atree")
newTree= tmp_tree.CloneTree(0)

I also tried the gc.disable() from the gc module.
However, I still got a list containing all None’s but the last index.

Is it possible to do such an operation with TTree objects?

[ ROOT v6.04 and v5.34.25, python 2.7.10 under macosx64 and x86_64 GNU/Linux machines ]


GC is to resolve cycles only: python uses ref-counts. Use SetDirectory() for tree ownership control, but being views only, makes no sense to keep trees alive w/o the file.

File refcount goes to zero after Get(). Python owns. Either keep alive, or set TFile.Open._creates to False (can find and close from gROOT.GetListOfFiles() as needed).