alokoko alokoko - 1 year ago 189
iOS Question

Release textures (GLKTextureInfo objects) allocated by GLKTextureLoader

New to developing on iOS and in particular the new OpenGL related features on iOS 5, so I apologize if any of my questions are so basic.

The app I am working on is designed to receive camera frames and display them on screen via OpenGL ES (the graphic folks will take over this and add the actual OpenGL drawing about which I know very little). The application is developed XCode4, and the target is iPhone4 running iOS 5. For the moment, I used the ARC and the GLKit functionality and all is working fine except for the memory leak in loading the images as texture. The app receives a "memory warning" very soon.

Specifically, I would like to ask how to release the textures allocated by

@property(retain) GLKTextureInfo *texture;

NSError *error;

self.texture = [GLKTextureLoader textureWithCGImage:image options:nil error:&error];

if (error)
NSLog(@"Error loading texture from image: %@",error);

is a quartz image built from the camera frame (sample code from apple). I know the problem is not in that part of the code since if I disable the assignment, the app does not receive the warning.

Answer Source

Super hacky solution I believe, but it seems to work:

Add the following before the assignment:

GLuint name =;
glDeleteTextures(1, &name);

If there's a more official way (or if this is the official way), I would appreciate if someone could let me know.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download