[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Ridiculous memory usage!



Curtiss Howard wrote:
... There are about 50 images total that are loaded all at
once and Python is using up somewhere in the neighborhood of 130MB!
I've checked and images are loaded once and only once.  The only
explanation for this behavior that I can think of is that Pygame is
keeping an 800x600x32 "raw copy" of every image in memory.  Is there
no better way than that?
python/SDL won't keep any 'extra copies' of images around, but your full sized images might be stored at 32 bpp, depending on what you are doing to them. here's a couple things that would give you a full 32bit image.

* the PNG images themselves could already be at 32bpp, when you load them in they will match whatever pixel depth the actual PNG file is.
* transform.rotozoom() will always produce 32bpp surfaces.
* calling Surface.convert() will also create 32bpp surfaces if the display depth is already at the depth.

it sounds like around 60 images at this resolution would grow to over 100MB. are you expecting the scaled images to be at only 8bpp? i guess you'll want to find out at what point they become 32bpp. the Surface.get_bitsize() function should help with that.

the only other way extraneous images would be lying around in memory is if the python GC is deciding not to free up some Surface objects.