I blit surfaces in my pygame file but the problem is they just stay there. My (hopefully temporary) solution was to just move them far off the window when they aren't in use (i.e. (-5000,0) ), but this decreases performance every time I blit a new surface. Is there any way to delete them? del doesn't seem to do it.
The memory of a Surface is freed when there is no reference to it anymore, when Python's garbage collection cleans it.
You don't need to use del, just make your program so that you don't refer to unused surfaces anywhere. You can assign None to it if not else.
Sometimes you don't need to keep creating new surfaces all the time but can just use the ones that you already have. But it works fine also to create new and have Python clear the old. I've written some screensaver like Pygame visualizers for VJing and installations way back and have had them running for days, constantly adding new images to the screen and removing old, no memory leaks. And never needed del.
Is there a way to delete Pygame Surfaces? Or any way to remove them from memory to increase performance?