I am new to Python, writing something with pygame and it is very bitmap intensive. Here are certain (current) facts about it:
- All graphics files have the potential to be reused at any point in a program instance.
- It can take up 1GB+ memory if I pre-load everything in the beginning, even when there are no duplicates.
- It is not hard to load the images when they are (almost) needed i.e. the file sizes are very small compared to the memory usage, and it is easy to predict what will come next.
There are many suggestions not to use del, and I do not know if that applies to my case. I have thought about utilizing the garbage collection mechanism, by implementing a resource manager that holds the only reference to any loaded image, and it juggles through different images, roughly by removing the reference for one while re-loading an other.
However, I am not very sure if this really frees any memory at any point, and I don’t know how make the GC to actually keep the memory down consistently, as it seems that gc calls is quite expensive (and by default too infrequent)
So in summary, I would like to know whether the method outlined above is worth a try, and if not I hope someone could teach me other ways such as properly using del, and whether that fits pygame. Any help will be appreciated.
Try this, see if its good enough. http://www.pygame.org/wiki/LazyImageLoading?parent=CookBook
Keep your initial texture manager design as simple as possible. Afterwards, if profiling says you need more performance, then optimize.