Memory Leak Django

Hello I have an issue with a memory leak, after a process the gc doesn’t collect numeric type varibles, I tried with del or casting the variables to none, then calling gc.collect. Do you have any suggestions ? We investigated with memory_profiler and managed to find those numeric varibles that are not cleaned by gc. I’m posting on the forum because I think that the issue is due to django’s memory management that does not release the memory after the process finishes. Thanks

Welcome @emmiraglia !

This is actually a Python issue and has nothing directly to do with Django. How memory is managed by Python can be different based upon which version and release of the compiler you are using.

Also keep in mind that your code runs within the context of a larger process. When a view finishes handling a request, the process running that view does not terminate.

If you’re really interesting in understanding how Python manages memory, you can start by reading the Memory Management — Python 3.12.4 documentation, Design and History FAQ — Python 3.12.4 documentation, and Garbage collector design docs. You’ll also find a number of relevent threads over at https://discuss.python.org/