diff --git a/bindings/pyroot/cppyy/CPyCppyy/src/API.cxx b/bindings/pyroot/cppyy/CPyCppyy/src/API.cxx index 2a666c4645942..f1e4a336bd825 100644 --- a/bindings/pyroot/cppyy/CPyCppyy/src/API.cxx +++ b/bindings/pyroot/cppyy/CPyCppyy/src/API.cxx @@ -88,7 +88,10 @@ static bool Initialize() // retrieve the main dictionary gMainDict = PyModule_GetDict( PyImport_AddModule(const_cast("__main__"))); - Py_INCREF(gMainDict); + // The gMainDict is borrowed, i.e. we are not calling Py_INCREF(gMainDict). + // Like this, we avoid unexpectedly affecting how long __main__ is kept + // alive. The gMainDict is only used in Exec(), ExecScript(), and Eval(), + // which should not be called after __main__ is garbage collected anyway. } // declare success ...