I am working on a 2D iPhone game using OpenGL ES and I continue to beat the 24 MB memory limit - my application continues to crash with error code 101. I tried very hard to find where the memory is, but the numbers in the tools are still much larger than I expected.
I launched the application using the tools Memory Monitor, Object Alloc, Leaks and OpenGL ES. When the application loads, free physical memory drops from 37 MB to 23 MB, the Alloc object takes about 7 MB, Leaks has two or three leaks in several bytes, the size of the Gart object is about 5 MB, and the Memory Monitor application takes about 14 MB real memory. I am puzzled at how memory happens - when I dig into Object Allocations, most of the memory is in textures, just like I would expect. But my own texture distribution counter and the size of the Gart object agree that textures should occupy about 5 MB.
I donโt know how to highlight anything else worth mentioning, and Object Alloc agrees. Where is the memory going? (I would be happy to provide more details if this is not enough.)
Update: I was really trying to find where I could allocate so much memory, but without any results. I am distinguished by the difference between the distribution of objects (~ 7 MB) and the use of real memory, as shown in Monitor Memory (~ 14 MB). Even if there were huge leaks or huge chunks of memory that I forgot about, they should appear in Object Allocations, right?
I already tried the usual suspect , i.e. UIImage with its caching, but this did not help. Is there a way to track the memory usage of the "debugger style", taking turns observing how each statement affects memory usage?
What I have found so far:
I use so much memory. It is not easy to measure the consumption of real memory, but after a big calculation, I think that the memory consumption is really large. My mistake.
I did not find a simple way to measure the memory used. The memory monitor numbers are accurate (these are the numbers that really matter), but the memory monitor cannot indicate where the memory is located. The Object Alloc tool is almost useless for tracking real memory usage. When I create a texture, the allocated memory counter rises for a while (reading the texture into memory), then drops (transferring texture data to OpenGL, freeing up). This is normal, but this does not always happen - sometimes the memory usage remains high even after the texture has been transferred to OpenGL and freed from "my" memory. This means that the total amount of memory allocated as shown by the Object Alloc tool is less than the actual total memory consumption, but more than the actual consumption minus the textures ( real โ textures < object alloc < real ). Go ahead.
I read the Programming Guide incorrectly. The 24 MB memory limit refers to textures and surfaces, not the whole application. The actual red line lies a little further, but I could not find any hard numbers. The consensus is that 25-30 MB is the ceiling.
When the system becomes short in memory, it begins to send a warning about the memory. Almost nothing frees me, but other applications free memory back to the system, especially Safari (which seems to cache websites). When the free memory, as shown on the memory monitor, is zero, the system begins to kill.
I had to bite a bullet and rewrite some parts of the code in order to be more efficient in memory, but I probably still click on it. If I had to develop another game, I would probably think of some kind of resource. With the current game, this is quite difficult, because the thing is in motion all the time and loading textures interferes, even if done in another thread. I would be very interested in how other people will solve this problem.
Please note that these are only my views, which do not have to be accurate. If I find out anything else about this, I will update the question. I will keep the question open if someone who understands this question answers, because all of these are more workarounds and conjectures than anything else.