It is very difficult, in general, for the process to "return memory back to the OS" (until the process is complete and the OS returns all memory, of course), because (in most cases, the implementation) that returns malloc cut from large blocks for efficiency, but the entire block cannot be returned if any part of it is still in use - which is why most standard C libraries do not even try.
For a worthy discussion in the context of Python, see, for example, here . Evan Jones fixed some problems with Python, as described here and here , but his patch is in the trunk with Python 2.5, so the problems you observe are definitely related to the system malloc package and not Python as such. Designation 2.6 is here and here .
A SO thread is here , where Hugh Allen quotes Firefox programmers in his answer that Mac OS X is a system in which it is basically impossible for the process of returning memory to the OS.
So, only completing the process, you can free his memory. For example, a long-term server may from time to time delete its state to disk and close it (using a tiny watchdog timer, system or custom, watch it and restart it). If you know that the next operation will take a long time for a short time, often you can os.fork , do holographic work in the child process and get the results (if any) to the parent process through when the child process ends. And so on and so forth.
Alex Martelli Jun 23 2018-10-10T00: 00Z
source share