EAGL - Double allocation of texture memory?

Hello-

I am using a 1024x1024 texture page in Opengl, and everything loads and displays fine. However when looking in Leaks tool, I see that the memory for the texutre page is double what it should be. (1024x1024x4 = 4.4mb, but 8.8 are allocated). I'm using code based on the Apple default OpenGL ES project. I think I'm freeing everything possible. Leaks says that either GLClear or GLRendererFloat are malloc'ing 4.2 mb.. Any ideas? Here is my texture loading code:

spriteImage = [UIImage imageNamed:[list objectAtIndex:i]].CGImage;
// Get the width and height of the image
width = CGImageGetWidth(spriteImage);
height = CGImageGetHeight(spriteImage);
// Texture dimensions must be a power of 2. If you write an application that allows users to supply an image,
// you'll want to add code that checks the dimensions and takes appropriate action if they are not a power of 2.

if(spriteImage) {
// Allocated memory needed for the bitmap context
spriteData = (GLubyte *) malloc(width * height * 4);
// Uses the bitmatp creation function provided by the Core Graphics framework.
spriteContext = CGBitmapContextCreate(spriteData, width, height, 8, width * 4, CGImageGetColorSpace(spriteImage), kCGImageAlphaPremultipliedLast);
// After you create the context, you can draw the sprite image to the context.
CGContextDrawImage(spriteContext, CGRectMake(0.0, 0.0, (CGFloat)width, (CGFloat)height), spriteImage);
// You don't need the context at this point, so you need to release it to avoid memory leaks.
CGContextRelease(spriteContext);

// Use OpenGL ES to generate a name for the texture.
glGenTextures(1, &spriteTextures);
// Bind the texture name.
glBindTexture(GLTEXTURE2D, spriteTextures
);
// Speidfy a 2D texture image, provideing the a pointer to the image data in memory
glTexImage2D(GLTEXTURE2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GLUNSIGNEDBYTE, spriteData);
// Release the image data
free(spriteData);

glTexParameteri(GLTEXTURE2D, GLTEXTURE_MINFILTER, GL_LINEAR);
glTexParameteri(GLTEXTURE2D, GLTEXTURE_MAGFILTER, GL_LINEAR);

}
CGContextRelease(spriteContext);
CGImageRelease(spriteImage);


Thank you very much

Skynet MBP, Mac OS X (10.5.4)

Posted on Oct 10, 2008 2:31 PM

Reply
3 replies

Oct 10, 2008 4:48 PM in response to typewriter

There shouldn't be any issues with freeing spriteData as you did in the original example. You should be able to use leaks to verify where all surviving allocations are from, and determine that it isn't spriteData.

The software renderer used by the simulator is quite different than the OpenGL implementation on the device. You should use leaks on the device and verify that the problem does, or does not, occur there. If it is Sim only, don't worry about it.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

EAGL - Double allocation of texture memory?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.