問題描述
剛開始在 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 對象)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!