Reputation:
I would know if it's possible to unload a image after use. In fact, I load a lot of image for the main, for the settings, the game and creadits too. But there are image useful in a part but completely useless in the three others. I mean for 90%, they are useful in only 1 part. So, I wonder if exist a way to delete the image from the memory of the program, and by the way make it less heavy...
Upvotes: 2
Views: 738
Reputation: 7361
The garbage collector will do it automatically when there are not anymore references to the images.
For example, say you have myimage = pygame.image.load('path/to/image)
. If at some point you set myimage = None
and you do not have any other reference to that image, the garbage collector will free the memory.
Of course you can also do del myimage
. The del
statement will delete the reference immediately (but not the object itself).
If your game is properly designed (with classes, functions) it's very likely that the garbage collector is already doing its work and you do not need to take care of deleting things.
Upvotes: 2