I have python scripts that calls a function foo
that performs some operations that uses say 10GB of memory and returns the small object res
to the main program. After printing res I delete the res, but top shows the ipython process is sill using about 1GB of memory. How can I ensure the process frees up all unused memory?
def foo(): .... # some complication operation return resif __name__ == "__main__": res = foo() print(res) del res
I tried using gc.collect() but the it does not change anything.I have read that sometimes the memory becomes fragmented and python can not reclaim all the memory.