0

My python program use more and more memory when running, I have used del to delete the big object I have created, and the top shows that the memory drops a little(about 1-3%) but there is still much memory not freed, it seems that python virtual machine does not return the memory, which is freed by del, to OS, so my question is:

1.Could I know how much memory is available in python virtual machine instead of the python process? If yes, how? And could I force virtual machine to return memory to OS?

2.Could two different python programs share the memory in python virtual machine? If not, will one of them return some memory to OS, when the other is in need of memory and OS has not too much memory available?

The question here Total memory used by Python process? did of some help for me, but it still not enough for me to solve my problem, my situation is: I have a Linux server and runs dozens of python daemons, one of them cost more and more memory when it runs, in order to free its memory I use del to delete some big object and combine with gc.collect() with the hope to free more memory, but it seems that it is not works fine, then I get the info that the memory is still handled by virtual machine instead of OS, so this is why the question 1 comes. And knowing how much memory this daemon cost did of some help, but I am also concern that this daemon could exhaust all the memory which may lead other daemons run out of memory, and this is the reason that I ask the question 2.

Thanks in advance.

buxizhizhoum
  • 1,719
  • 1
  • 23
  • 32
  • 2
    Just because `del` is called, doesn't mean the memory is freed at once. The garbage collector acts periodically to recollect unreferenced memory on the heap. You can speed this up by invoking `import gc; gc.collect()`. – cs95 Sep 14 '17 at 08:17
  • Possible duplicate of [Total memory used by Python process?](https://stackoverflow.com/questions/938733/total-memory-used-by-python-process) – Reblochon Masque Sep 14 '17 at 08:18
  • You probably should look for large objects loitering in a collection after you think you have discarded them. Assigning `None` to placeholders is sometime a good idea. – Reblochon Masque Sep 14 '17 at 08:20

0 Answers0