I wrote a Python program that acts on a large input file to create a few million objects representing triangles. The algorithm is:
As other answers already say, Python can keep from releasing memory to the OS even if it's no longer in use by Python code (so gc.collect()
doesn't free anything) especially in a long-running program. Anyway if you're on Linux you can try to release memory by invoking directly the libc function malloc_trim
(man page).
Something like:
import ctypes
libc = ctypes.CDLL("libc.so.6")
libc.malloc_trim(0)