pygame-ce
pygame-ce copied to clipboard
display.set_mode memory leak with SCALED flag
trafficstars
While testing some stuff, I noticed that there is a memory leak in display.set_mode, but only in specific conditions. To be exact, when the function calls PG_CreateSurface. It is called for example, when you pass SCALED flag. Looks like that surface is later not deleted. It can be shown with the following code
import pygame
import psutil
import os
while True:
pygame.display.set_mode((800, 600), flags=pygame.SCALED)
print(f"Memory usage: {psutil.Process(os.getpid()).memory_info().rss / 1024 / 1024:.2f} MB")
It uses the psutil, which has to be pip installed, but you can notice it with
import pygame
while True:
pygame.display.set_mode((800, 600), flags=pygame.SCALED)
And looking at the Windows Task Manager, or whatever alternative for your OS