Data stays in memory for too long after a query

can i control this somehow?
1 query occupies 3gb + of memory, so if i execute too many i’m gonna get into trouble
because the system frees up the space after 5-15 minutes