I find that the macro below has a memory leak. I am confused because I thought python should be garbage collected. I am using ROOT version 5.34/20
for i in range(0,300000):
Python is garbage collected, but only for Python objects and by extension all C++ objects that those Python objects control. For C++ objects that are returned by pointer, and therefore are unclear in their ownership, the assumption is that C++ will take care of the memory management.
You can adjust that for individual methods, though. For example here, to make sure that Python takes ownership of the C++ object bound with ‘data1’, set the _creates member of the generate function:
ROOT.RooExponential.generate._creates = True