I've just done a mega-memory trace of my app and I've found that every time game's images are loaded (each time you start the game from the main menu) living memory increases like 1 or 1.5 MB, which is quite critical! I've traced where these allocations came from and I've found that come from OpenGL's function glTexImage2D. Each call on this function allocates a 1MB Malloc which seems not to be released after that, so it keeps alive...
I've searched the whole code and I've found that this method is only used in a function inside the Texture2D.m class. Here is the function and the dealloc method (I think last one is correct, but I'm not sure so I copy it too):
I've also found a strange thing that I don't know how it works and why it's like is...
The Texture2D.m class (which I've taken from a tutorial) seems to be split in some parts divided by the "@implementation" and "@end" words, so there are one for "Texture2D", one for "Texture2D (Image)", one for "Texture2D (Text)", and one for "Texture2D (Drawing)", and I have to say that only the "Texture2D" and the "Texture2D (Drawing)" parts have a dealloc method before the "@end" line, I don't know it's what can be causing the leaks (sorry, maybe it's a quite newbie question, but I don't know exactly how this works and I'm get easily lost with this)...
Increasing memory by 1MB sounds about right for a 512x512 texture. The memory should be returned when you release the Texture2D and the dealloc is called but the system, though. The the glDeleteTextures line will delete the texture which should free the memory.
Regarding the Texture2D (Image) Texture2D (Text) Texture2D (Drawing), the author of the file used "categories" to divide up the implementation. It's OK that there's only one dealloc, because it's still just one class.
EDIT: I'd add an NSLog in the dealloc to find out if it's getting called. If dealloc is never getting called then the memory is never getting freed.
Why are you re-loading the images each time? Why not load them once, during start up, and keep the memory resident throughout the time? From your other threads it seems you only have 20mb or so of images? This should be a small enough amount to load once.
As for why it's leaking, have you checked that you're calling dealloc on all the images you load?
__________________
Visit Mr Jack Games for my blog and more about my games