Implemented Martin's suggestion to clear the free lists during the garbage collection of the highest generation.
diff --git a/Objects/frameobject.c b/Objects/frameobject.c
index df9c2e0..025431e 100644
--- a/Objects/frameobject.c
+++ b/Objects/frameobject.c
@@ -889,10 +889,11 @@
}
/* Clear out the free list */
-
-void
-PyFrame_Fini(void)
+int
+PyFrame_ClearFreeList(void)
{
+ int freelist_size = numfree;
+
while (free_list != NULL) {
PyFrameObject *f = free_list;
free_list = free_list->f_back;
@@ -900,6 +901,13 @@
--numfree;
}
assert(numfree == 0);
+ return freelist_size;
+}
+
+void
+PyFrame_Fini(void)
+{
+ (void)PyFrame_ClearFreeList();
Py_XDECREF(builtin_object);
builtin_object = NULL;
}