'Can I configure the rate of garbage collection python?

I have a python program and it was getting killed due to an out of memory error. I was using some deep recursion so i decided to use gc.collect() at the beginning to the method.

This solved the problem but and the program is no longer killed. Does anyone know why I had to call garbage collector and it wasn't automatically taken care of?

Now I worry that this is slowing down my program and I wonder is there a way to configure how/how often garbage collection is complete from outside my application? (without calling gc.collect() from the code)

PS. this was not a problem on my macos, only when I deployed the code to a linux VM on GCP



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source