bpo-38962: Fix reference leak in the per-subinterpreter gc (GH-17457) · python/cpython@ac0e1c2 (original) (raw)

Original file line number Diff line number Diff line change
@@ -1253,17 +1253,16 @@ finalize_interp_clear(PyThreadState *tstate)
1253 1253 {
1254 1254 int is_main_interp = _Py_IsMainInterpreter(tstate);
1255 1255
1256 -/* bpo-36854: Explicitly clear the codec registry
1257 - and trigger a GC collection */
1258 1256 PyInterpreterState *interp = tstate->interp;
1259 -Py_CLEAR(interp->codec_search_path);
1260 -Py_CLEAR(interp->codec_search_cache);
1261 -Py_CLEAR(interp->codec_error_registry);
1262 -_PyGC_CollectNoFail();
1263 1257
1264 1258 /* Clear interpreter state and all thread states */
1265 1259 PyInterpreterState_Clear(tstate->interp);
1266 1260
1261 +/* Trigger a GC collection on subinterpreters*/
1262 +if (!is_main_interp) {
1263 +_PyGC_CollectNoFail();
1264 + }
1265 +
1267 1266 finalize_interp_types(tstate, is_main_interp);
1268 1267
1269 1268 if (is_main_interp) {