Skip to content

Commit a2fe3d5

Browse files
committed
[PyROOT] Set memory policy to "strict"
PyROOT has many memory leaks, which is a major pain point for people using it for long-running scripts in batch jobs. One source of memory leaks was indentified to be the "heuristic memory policy" of PyROOT. This means that PyROOT assumes that every non-const pointer member function argument was interpreted as the object taking ownership if the argument. For examle, take the non-owning RooLinkedList container. It has a `RooLinkedList::Add(RooAbsArg *arg)` method. PyROOT wrongly assumes that this means the RooLinkedList takes ownership of arg, and it drops the PyROOT overship. Nobody feels responsible for deleting the object anymore, and there is a memory leak or `arg`. That particular leak was reported in this forum post: https://root-forum.cern.ch/t/memory-leak-in-fits/56249 Function parameters of type `T *` are very common in ROOT, and only rarely do they imply ownership transfer. So changing the memory policy to "strict" would surely fix also many other memory leaks that are not reported so far. In fact, upstream cppyy doesn't even have this heuristic memory policy anymore! So moving PyROOT also to the strict memory policy closes the gap between PyROOT and cppyy. The potential drawback of this change are crashes in usercode if memory is not properly managed. But these problems should either be fixed by: * the user * dedicated pythonizations for these methods to manage shared ownership via Python reference counters (i.e., setting the parameter as an attribute of the object that the member function was called on) This follows up on PR #4294, in particular it reverts 3a12063.
1 parent d016feb commit a2fe3d5

File tree

1 file changed

+0
-5
lines changed
  • bindings/pyroot/pythonizations/python/ROOT

1 file changed

+0
-5
lines changed

bindings/pyroot/pythonizations/python/ROOT/_facade.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,6 @@ def _finalSetup(self):
204204
if not self.gROOT.IsBatch() and self.PyConfig.StartGUIThread:
205205
self.app.init_graphics()
206206

207-
# Set memory policy to kUseHeuristics.
208-
# This restores the default in PyROOT which was changed
209-
# by new Cppyy
210-
self.SetMemoryPolicy(self.kMemoryHeuristics)
211-
212207
# Redirect lookups to cppyy's global namespace
213208
self.__class__.__getattr__ = self._fallback_getattr
214209
self.__class__.__setattr__ = lambda self, name, val: setattr(gbl_namespace, name, val)

0 commit comments

Comments
 (0)