释放由GLKTextureLoader分配的纹理(GLKTextureInfo对象) [英] Release textures (GLKTextureInfo objects) allocated by GLKTextureLoader

查看:801
本文介绍了释放由GLKTextureLoader分配的纹理(GLKTextureInfo对象)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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.

应用I我正在努力接收相机帧并通过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);
    }
}

图片是从相机框架构建的石英图像(来自苹果的示例代码)。我知道问题不在代码的那一部分,因为如果我禁用分配,应用程序就不会收到警告。

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对象)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆