I would then like to have the clone exist in memory after the code exits the call to the function, but I cannot manage to keep it alive. Is there any way this can be done?
if the python side needs to manage the object, a reference needs to exist somewhere. If you rely on the C++ side to take over management, you can do:import ROOT
ROOT.SetOwnership(newHisto, False)
The reason that python thinks it has ownership is b/c Clone() creates a new object. You can also tell it that Clone() does not create new objects (but make sure to manage them on the C++ side then, e.g. on a TCanvas), by globally setting:someHisto.__class__.Clone._creates = False
But again, to emphasize, that’s a global change for all calls to Clone() on that type of histo everywhere.