diff options
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/gcmodule.c | 22 | ||||
-rw-r--r-- | Modules/mmapmodule.c | 4 |
2 files changed, 26 insertions, 0 deletions
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c index d449a2b..f332231 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) @@ -687,6 +688,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 @@ -839,6 +855,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 = PyUnicode_FromString("garbage collection"); diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index c83af0d..b77dda5 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -1043,6 +1043,10 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict) "mmap invalid access parameter."); } + if (prot == PROT_READ) { + access = ACCESS_READ; + } + #ifdef HAVE_FSTAT # ifdef __VMS /* on OpenVMS we must ensure that all bytes are written to the file */ |