Take the 2-minute tour ×

I have an iOS opengl es 2.0 app that needs to use a TON of large textures. Ideally 4096x4096. I have a struct array that contains all the info about the texture, and as I need to use each one I glGenTextures a new texture id and load the image there, free up the uiimage, etc. That all works great.

My app uses a bunch of textures for UI, image processing, etc. About 4-5 of the 15 I'm using for all of that are 4k x 4k. Rest are smaller. And then these load-as-needed textures are also 4k.

On loading about the 4th-5th of those the app crashes HARD. No console or debug. Just quits to the springboard in the middle of trying to load the next texture.

I don't have a memory leak - I ran instruments. I'm using ARC. I can post the crash report from the Organizer but it doesn't have much info. Just that my app's rpages was 170504.

I could post the image load code but its the same code I've used on all my apps for years. The new thing is pushing the system that hard and trying to load that many large textures.

Q1: Anyone have experience with using a ton of large textures?

So I resolved to the fact that I'll have to do preview res stuff at 1024x1024 and then final res stuff at 4096. The 1k images are now loading as needed and staying loaded. The 4k images will all be loaded one at a time into the same texture to be used and then move on to the next.

I wrote into my image loader a preview parameter and when set it shrinks the image to fit in 1024 during the load. Now Instead of crashing on the 4th or 5th I can add textures 'all day'. My GUESS is that I could do 16x as many as before. But I only need like 20-30 at a time. (only!) So far I've tried 20 with no memory warnings or crashes.

However.. if the app keeps running, because my textures are loaded at unique texture ids, at some point I would hit that spot where I need to unload one that's no longer needed to load the next one. This is probably very simple, but....

Q2: How do I free up a texture that's at an texture id when I no longer need it?

Q3: Will a memory warning tell me that I need to free up an open gl texture?

Q4: Aren't textures loaded on the PVR chip? Are they or how are they even taking up the phone's memory?


share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Removing Texture: You have to use this GL call from the main thread.

glDeleteTextures(1, &_texture);

Memory warning is a general call to the application. It will not give you specific information. It is always better to remove unwanted textures from the memory if they are not needed anymore. Eg: We usually remove textures used in menu when the user moves to the In-Game screens, they are reloaded again when the user navigates back. This is much easier to manage memory than waiting for the system to call memory warning.

When you load PNG image, the data is decompressed and stored raw as array of colors per pixel. A 1K texture will use 4 mb despite of content/colors in the image. PVR is a hardware decompression chip which will decompress realtime when the image is used by the GPU, and the image file size you see is what memory it uses.

share|improve this answer
Thanks. That's what I was looking for. I knew it would be something simple. When you teach yourself opengl it's easy to miss the small stuff. –  badweasel Aug 20 '13 at 6:29
Can I ask though.. you say when you load a PNG the data is "decompressed and stored raw".. but then you talk about PVR being a hardware decompression chip and it decompressed the image real time.. so is it storing it in the chip compressed or decompressed? without using the pvr format is there a way to store it compressed on the chip to give you more room? Or is that the only way? Apple claims that the pvr format might not always be supported so I've avoided it. Do you use it? –  badweasel Aug 20 '13 at 6:32
We usually don't use PVR, but are planning to move from PNG to PVR. PVR file is loaded and stored in the memory and is sent to the GPU directly, the GPU decompresses the file when it uses. So the memory used is just the file size. The decompression happens in the GPU itself. PNG and PVR are 2 good formats, I know. Apple's devices use PVR for compressed files, no other compression format is supported as far as I know. –  codetiger Aug 20 '13 at 12:40
but when we load in a png or a jpg.. is it converting it to a PVR internally? Will I get any memory benefits from using PVR as a file type? –  badweasel Aug 20 '13 at 22:53
With PVR, yes you will get memory benifits. Png is not converted to pvr. Pvr conversion is time consuming. When you load png, it is stored as uncompressed pixel info –  codetiger Aug 21 '13 at 1:58
show 1 more comment

Your Answer


