display.set_mode memory leak with SCALED flag
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
No memory leak for me on Ubuntu 25.04 and standard pygame-ce 2.5.5 release install
No memory leak for me either. Arch/GNOME with pygame-ce 2.5.5.
Windows 11: I have been running this version:
import pygame
while True:
pygame.display.set_mode((800, 600), flags=pygame.SCALED)
For a few hours, but without any visible increased memory usage. (Maybe it's psutil which has memory leak?)