I have Django project where I need to get data from postgres DB and then manipulate with it (1GB in postgres). After that when I executed all postgres data what I needed my ram increase, after another operation like this RAM also increase and so on...
If I have 64GB RAM and after execution postgres data my RAM increase ~1GB then if I run that function 10 times my ram will be ~10GB
I tried to delete all variables from Python with del or gc, but after that I also have full RAM.
Only option to clear RAM is to close Django project.
Is there option to clear RAM after I execute data from postgres?
This is an example how I get data from postgres. I use psycopg2 library.
This is Django view, and after I go to this it runs this peace of code.
from django.http import HttpResponse
import psycopg2
def index(request):
    con = psycopg2.connect(host="localhost", database="database", user="postgres", password="postgres")
    cur = con.cursor()
    text = "select * from table"
    cur.execute(text)
    text = cur.fetchall()
    cur.close()
    con.close()
    test_len = len(text)
    del text
    return HttpResponse(test_len)
    
Every time I refresh page I get all data from table And RAM increases
One more example:
when I run python3 mnanage.py runserver my ram is 2GB, after I refresh page it increases to 13GB and then drops to 7.7GB, and after that if I resresh again and again I still get RAM on 7.7GB, but after I am getting data I delete this variable. why I still get 7.7GB RAM?
 
     
    