Hi,
I’m observing a huge memory leak in PyROOT trying to retrieve many objects (RooStats::HypoTestInverterResults and RooFitResults) from many different files.
The following snippet is problematic:
194 for wsId in wsNameMap:
195 name = wsNameMap[wsId]
196
197 #ht = GetHypoTestResultFromFile(f, name)
198 ht = f.Get(name)
199 if ht is None:
200 continue
201
202 #del ht
203 continue
wsNameMap simply contains a unique string to a name of an object in the open file. This map is made with filtering f.GetListOfKeys(), and does not cause the leak: simply starting the loop wth the continue statement keeps memory usage constant. That leads be to believe that I have no problems with unclosed files. (The statement f.Close() is in fact right outside this loop, after some checks on the HypoTestResult and the RooFitResult are done.)
When executing this snippet on 100 inputs files, memory leaks. For good measure I loop over every file 50 times, and this leaks MB’s by the second.
The commented line in 202 does not help. The utility function GetHypoTestResultFromFile is implemented like this:
323 def GetHypoTestResultFromFile(f, name):
324 return GetObjectFromFile(f, name, "RooStats::HypoTestInverterResult")
325
326 def GetFitResultFromFile(f, name):
327 return GetObjectFromFile(f, name, "RooFitResult")
328
329 def GetObjectFromFile(f, name, type):
330 if f.IsZombie():
331 return None
332
333 result = f.Get(name)
334 if not result or result is None or result.ClassName() != type:
335 if result:
336 print result.ClassName()
337 print "Cannot open {1} {0}".format(name, type)
338 return None
339
340 ROOT.SetOwnership(result, True )
341 return result
The leaks are observed both with and without line 340. Also switching between the strict and heuristic memory management does not help. I’m at a loss why this kind of programming should cause a leak - it’s not unusual to read O(50k) RooFit results and hypothesis tests. Any help would be greatly appreciated.
In case it is relevant: my ROOT build is 6.04.02-x86_64-slc6-gcc48-opt, using Python 2.7.4.
Cheers,
Geert-Jan