summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorChristian Heimes <christian@cheimes.de>2008-02-14 12:47:33 (GMT)
committerChristian Heimes <christian@cheimes.de>2008-02-14 12:47:33 (GMT)
commit3b718a79af900fdacaf0b825137f69eadc753765 (patch)
tree71cbe9fcb7b94a2611e5f62cf329285270615e22 /Modules
parent50361d4d9b3e8729aa535c3dfde3d9d2ad899d47 (diff)
downloadcpython-3b718a79af900fdacaf0b825137f69eadc753765.zip
cpython-3b718a79af900fdacaf0b825137f69eadc753765.tar.gz
cpython-3b718a79af900fdacaf0b825137f69eadc753765.tar.bz2
Implemented Martin's suggestion to clear the free lists during the garbage collection of the highest generation.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/gcmodule.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c
index 522cc89..4f8c85f 100644
--- a/Modules/gcmodule.c
+++ b/Modules/gcmodule.c
@@ -19,6 +19,7 @@
*/
#include "Python.h"
+#include "frameobject.h" /* for PyFrame_ClearFreeList */
/* Get an object's GC head */
#define AS_GC(o) ((PyGC_Head *)(o)-1)
@@ -722,6 +723,21 @@ delete_garbage(PyGC_Head *collectable, PyGC_Head *old)
}
}
+/* Clear all free lists
+ * All free lists are cleared during the collection of the highest generation.
+ * Allocated items in the free list may keep a pymalloc arena occupied.
+ * Clearing the free lists may give back memory to the OS earlier.
+ */
+static void
+clear_freelists(void)
+{
+ (void)PyMethod_ClearFreeList();
+ (void)PyFrame_ClearFreeList();
+ (void)PyCFunction_ClearFreeList();
+ (void)PyTuple_ClearFreeList();
+ (void)PyUnicode_ClearFreeList();
+}
+
/* This is the main function. Read this to understand how the
* collection process works. */
static Py_ssize_t
@@ -874,6 +890,12 @@ collect(int generation)
*/
(void)handle_finalizers(&finalizers, old);
+ /* Clear free list only during the collection of the higest
+ * generation */
+ if (generation == NUM_GENERATIONS-1) {
+ clear_freelists();
+ }
+
if (PyErr_Occurred()) {
if (gc_str == NULL)
gc_str = PyString_FromString("garbage collection");