ios - opengl中的内存增长

标签 ios opengl-es memory-leaks paint

我的绘画应用程序中有更改画笔的代码。一切正常,但我发现,如果我多次调用该方法,内存不会释放,并且会越来越大...而且我找不到它在哪里?

- (void)setBrush:(UIImage *)brush withColor:(UIColor *)color andOpacity:(CGFloat)opacity andSize:(CGFloat)size {
CGImageRef brushImage;
CGContextRef brushContext;
GLubyte *brushData;
size_t width, height;
brushImage = brush.CGImage;
width = CGImageGetWidth(brushImage);
height = CGImageGetHeight(brushImage);
if(brushImage) {
    brushData = (GLubyte *) calloc(width * height * 4, sizeof(GLubyte));
    brushContext = CGBitmapContextCreate(brushData, width, height, 8, width * 4, CGImageGetColorSpace(brushImage), (CGBitmapInfo)kCGImageAlphaPremultipliedFirst);
    CGContextDrawImage(brushContext, CGRectMake(0.0, 0.0, (CGFloat)width, (CGFloat)height), brushImage);
    CGContextRelease(brushContext);
    glGenTextures(1, &brushTexture);
    glBindTexture(GL_TEXTURE_2D, brushTexture);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, brushData);
    free(brushData);
}
CGColorRef clr = [color CGColor];
const CGFloat *components = CGColorGetComponents(clr);
CGFloat red = components[0];
CGFloat green = components[1];
CGFloat blue = components[2];
glColor4f(red * opacity/3, green * opacity/3, blue * opacity/3, opacity/3);
glPointSize(width * size / 2);
}

它可能在哪里,它是如何纠正的?

最佳答案

您永远不会删除使用 glGenTextures() 创建的纹理,因此您只需分配越来越多的空间来容纳所有纹理数据。

关于ios - opengl中的内存增长,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20785946/

相关文章:

iphone - View 和 View Controller

objective-c - 哪些 iOS 框架最值得学习?按什么顺序学习?

java - 如何才能不发生内存泄漏 getInstance()

c++ - Valgrind 在定义 char* 数组时报告内存泄漏

java - 当我尝试创建客户端时 Redisson 内存泄漏

ios - 应用程序 :openURL:options: look like? 的 Swift 2 方法签名是什么

ios - 如何快速更改 Controller View 某些部分的颜色?

android - 尽管更改渲染模式,GLSurfaceView 仍持续渲染

android - OpenGL ES 2.0纯色和色值精度问题

iOS OpenGL ES Analyzer 列出 "Non-Existent Framebuffer Attachment"和 "Missing Framebuffer Attachment",但 FBO 有效