Skip to content

Commit

Permalink
bpo-1635741: Explict GC collect after PyInterpreterState_Clear() (pyt…
Browse files Browse the repository at this point in the history
…honGH-21902)

Fix a reference cycle by triggering an explicit GC collection
after calling PyInterpreterState_Clear().
  • Loading branch information
shihai1991 authored and Seth Sims committed Oct 18, 2020
1 parent 1e3285b commit 4d20475
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions Python/pylifecycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 4d20475

Please sign in to comment.