刚开始在 iOS 上进行开发,尤其是 iOS 5 上与 OpenGL 相关的新功能,所以如果我的任何问题都非常基础,我深表歉意.
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.
我正在开发的应用程序旨在接收相机帧并通过 OpenGL ES 在屏幕上显示它们(图形人员将接管它并添加我知之甚少的实际 OpenGL 绘图).该应用程序是 XCode4 开发的,目标是运行 iOS 5 的 iPhone4.目前,我使用了 ARC 和 GLKit 功能,除了将图像加载为纹理时出现内存泄漏外,一切都运行良好.该应用很快就会收到内存警告".
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;
-(void)setTextureCGImage:(CGImageRef)image
{
NSError *error;
self.texture = [GLKTextureLoader textureWithCGImage:image options:nil error:&error];
if (error)
{
NSLog(@"Error loading texture from image: %@",error);
}
}
image
是从相机框架构建的石英图像(来自苹果的示例代码).我知道问题不在代码的那部分,因为如果我禁用分配,应用程序不会收到警告.
The image
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.
我相信超级 hacky 解决方案,但它似乎有效:
Super hacky solution I believe, but it seems to work:
在赋值前添加以下内容:
Add the following before the assignment:
GLuint name = self.texture.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.
这篇关于释放由 GLKTextureLoader 分配的纹理(GLKTextureInfo 对象)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!