I am currently developing an iOS application (iPad and iPhone) that uses OpenGL ES 1.0 to render some basic textures. I use atlases to store and represent my textures.
My main atlas is relatively large (2000x2000), but my internal algorithms load and resize the texture to 2048x2048, since OpenGL ES only accepts texture power of size 2. I can draw tiles, everything is fine on this side.
I encounter a serious memory leak every time I try to load and unload (destroy) a texture. This should happen in the final version, but I needed to make sure that my loading and unloading were ok. In memory, the texture takes up 2048x2048x4 (RGBA) bytes = 16 MB approx. This is a huge amount of bytes, so you understand that the problem is quite annoying to me (iOS kills the application in a few minutes ..)
When I load the texture, the devices show that the total memory used by the application is increased by 16 MB, this is correct (I use the "Real memory" column). The problem arises when I need to destroy a texture in order to free all the possible bytes it uses: it never loses 16 MB ... and since I load and unload in a loop, memory continues to be used and never freed.
Here I load the textures:
GLubyte *outData = malloc((_dataWidth * _dataHeight * 4) * sizeof(*outData)); GLuint _texture;
This is how I unload the texture (this is called, I checked)
glDeleteTextures(1, &_texture);
I used glGetError () everywhere to check if an error occurred, but it always returns 0 (even after glDeleteTexture).
Does anyone have any ideas? Thanks!
source share