pygame-ce icon indicating copy to clipboard operation
pygame-ce copied to clipboard

display.set_mode memory leak with SCALED flag

Open MightyJosip opened this issue 10 months ago • 3 comments

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

MightyJosip avatar Jun 15 '25 13:06 MightyJosip

No memory leak for me on Ubuntu 25.04 and standard pygame-ce 2.5.5 release install

ankith26 avatar Jun 15 '25 15:06 ankith26

No memory leak for me either. Arch/GNOME with pygame-ce 2.5.5.

AntonisDevStuff avatar Jun 15 '25 21:06 AntonisDevStuff

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?)

gresm avatar Oct 01 '25 20:10 gresm