From: Hai Shi Date: Mon, 17 Aug 2020 20:36:19 +0000 (+0800) Subject: bpo-1635741: Explict GC collect after PyInterpreterState_Clear() (GH-21902) X-Git-Tag: v3.10.0a1~238 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8aa163eea6b0fb4693f6c0a314d4f2ccada51d70;p=thirdparty%2FPython%2Fcpython.git bpo-1635741: Explict GC collect after PyInterpreterState_Clear() (GH-21902) Fix a reference cycle by triggering an explicit GC collection after calling PyInterpreterState_Clear(). --- diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 2d219a4a3a8b..ab5a6767864d 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -1286,10 +1286,8 @@ finalize_interp_clear(PyThreadState *tstate) /* Clear interpreter state and all thread states */ PyInterpreterState_Clear(tstate->interp); - /* Trigger a GC collection on subinterpreters*/ - if (!is_main_interp) { - _PyGC_CollectNoFail(); - } + /* Last explicit GC collection */ + _PyGC_CollectNoFail(); /* Clear all loghooks */ /* Both _PySys_Audit function and users still need PyObject, such as tuple.