@@ -1070,14 +1070,33 @@ delete_garbage(PyThreadState *tstate, GCState *gcstate,
1070
1070
static void
1071
1071
clear_freelists (PyInterpreterState * interp )
1072
1072
{
1073
+ // TODO: Unify with clear_all_freelists
1073
1074
_PyTuple_ClearFreeList (interp );
1074
1075
_PyFloat_ClearFreeList (interp );
1075
- _PyList_ClearFreeList (interp );
1076
1076
_PyDict_ClearFreeList (interp );
1077
1077
_PyAsyncGen_ClearFreeLists (interp );
1078
1078
_PyContext_ClearFreeList (interp );
1079
1079
}
1080
1080
1081
+ static void
1082
+ clear_all_freelists (PyInterpreterState * interp )
1083
+ {
1084
+ clear_freelists (interp );
1085
+ #if defined(Py_GIL_DISABLED )
1086
+ HEAD_LOCK (& _PyRuntime );
1087
+ _PyThreadStateImpl * tstate = (_PyThreadStateImpl * )interp -> threads .head ;
1088
+ while (tstate != NULL ) {
1089
+ _PyList_ClearFreeList (& tstate -> freelist_state );
1090
+ tstate = tstate -> base .next ;
1091
+ }
1092
+ HEAD_UNLOCK (& _PyRuntime );
1093
+ #else
1094
+ // Only free-lists per interpreter are existed.
1095
+ PyFreeListState * state = _PyFreeListState_GET ();
1096
+ _PyList_ClearFreeList (state );
1097
+ #endif
1098
+ }
1099
+
1081
1100
// Show stats for objects in each generations
1082
1101
static void
1083
1102
show_stats_each_generations (GCState * gcstate )
@@ -1486,6 +1505,7 @@ gc_collect_main(PyThreadState *tstate, int generation, _PyGC_Reason reason)
1486
1505
* generation */
1487
1506
if (generation == NUM_GENERATIONS - 1 ) {
1488
1507
clear_freelists (tstate -> interp );
1508
+ clear_all_freelists (tstate -> interp );
1489
1509
}
1490
1510
1491
1511
if (_PyErr_Occurred (tstate )) {
0 commit comments