]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-1635741: Explict GC collect after PyInterpreterState_Clear() (GH-21902)
authorHai Shi <shihai1992@gmail.com>
Mon, 17 Aug 2020 20:36:19 +0000 (04:36 +0800)
committerGitHub <noreply@github.com>
Mon, 17 Aug 2020 20:36:19 +0000 (22:36 +0200)
Fix a reference cycle by triggering an explicit GC collection
after calling PyInterpreterState_Clear().

Python/pylifecycle.c

index 2d219a4a3a8b0db5a9c4fd8497565491aa413dd2..ab5a6767864dc596bdb94a8163c88888fa391062 100644 (file)
@@ -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.