問(wèn)題描述
剛開(kāi)始在 iOS 上進(jìn)行開(kāi)發(fā),尤其是 iOS 5 上與 OpenGL 相關(guān)的新功能,所以如果我的任何問(wèn)題都非常基礎(chǔ),我深表歉意.
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.
我正在開(kāi)發(fā)的應(yīng)用程序旨在接收相機(jī)幀并通過(guò) OpenGL ES 在屏幕上顯示它們(圖形人員將接管它并添加我知之甚少的實(shí)際 OpenGL 繪圖).該應(yīng)用程序是 XCode4 開(kāi)發(fā)的,目標(biāo)是運(yùn)行 iOS 5 的 iPhone4.目前,我使用了 ARC 和 GLKit 功能,除了將圖像加載為紋理時(shí)出現(xiàn)內(nèi)存泄漏外,一切都運(yùn)行良好.該應(yīng)用很快就會(huì)收到內(nèi)存警告".
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.
具體想問(wèn)一下怎么釋放分配的貼圖
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
是從相機(jī)框架構(gòu)建的石英圖像(來(lái)自蘋(píng)果的示例代碼).我知道問(wèn)題不在代碼的那部分,因?yàn)槿绻医梅峙洌瑧?yīng)用程序不會(huì)收到警告.
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.
推薦答案
我相信超級(jí) hacky 解決方案,但它似乎有效:
Super hacky solution I believe, but it seems to work:
在賦值前添加以下內(nèi)容:
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.
這篇關(guān)于釋放由 GLKTextureLoader 分配的紋理(GLKTextureInfo 對(duì)象)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!