0

У меня возникли проблемы, удаляемый мои текстуры OpenGL ES созданы с помощью Quartz 2D и основной текст, как показано ниже:Невозможно освободить Quartz 2D и основной текст создан Изображения

- (void)drawText:(CGContextRef)contextP startX:(float)x startY:(float) 
y withText:(NSString *)standString 
{ 
    CGContextTranslateCTM(contextP, 0, (bottom-top)*2); 
    CGContextScaleCTM(contextP, 1.0, -1.0); 

    CGRect frameText = CGRectMake(1, 0, (right-left)*2, (bottom-top)*2); 

    NSMutableAttributedString * attrString = [[NSMutableAttributedString alloc] initWithString:standString]; 
    [attrString addAttribute:NSFontAttributeName 
         value:[UIFont fontWithName:@"Helvetica-Bold" size:12.0] 
         range:NSMakeRange(0, attrString.length)]; 

    CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((__bridge CFAttributedStringRef)(attrString)); 
    struct CGPath * p = CGPathCreateMutable(); 
    CGPathAddRect(p, NULL, frameText); 
    CTFrameRef frame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0,0), p, NULL); 

    CTFrameDraw(frame, contextP); 

    CFRelease(framesetter); 
    CFRelease(frame); 
    CGPathRelease(p); 

    standString = nil; 
    attrString = nil; 

} 

- (UIImage *)drawTexture : (NSArray *)verticesPassed : (UIColor *)statusColour : (NSString *)standString { 

    CGColorSpaceRef rgbColorSpace = CGColorSpaceCreateDeviceRGB(); 

    CGRect shp = [self boundFromFrame:verticesPassed]; 

    CGContextRef conPattern = CGBitmapContextCreate(NULL, 
                shp.size.width*sceneScalar, 
                shp.size.height*sceneScalar, 
                8, 
                0, 
                rgbColorSpace, 
                (CGBitmapInfo)kCGImageAlphaPremultipliedFirst); 

    CGColorSpaceRelease(rgbColorSpace); 

    CGContextSetLineWidth(conPattern, 2); 
    CGContextSetStrokeColorWithColor(conPattern, [UIColor blackColor].CGColor); 

    Line * start = [sortedVertices objectAtIndex:0]; 
    StandPoint * startPoint = start.origin; 

    CGContextMoveToPoint(conPattern, ([startPoint.x floatValue]-shp.origin.x)*sceneScalar , ([startPoint.y floatValue]-shp.origin.y)*sceneScalar); 
    for (Line * vertice in sortedVertices) { 
     StandPoint * standPoint = vertice.origin; 
     CGContextAddLineToPoint(conPattern, ([standPoint.x floatValue]-shp.origin.x)*sceneScalar, ([standPoint.y floatValue]-shp.origin.y)*sceneScalar); 
    } 

    CGContextAddLineToPoint(conPattern, ([startPoint.x floatValue]-shp.origin.x)*sceneScalar , ([startPoint.y floatValue]-shp.origin.y)*sceneScalar); 

    CGContextSetFillColorWithColor(conPattern, statusColour.CGColor); 

    CGContextDrawPath(conPattern, kCGPathFillStroke); 

    [self drawText:conPattern startX:0 startY:20 withText:standString]; 

    CGImageRef cgImage = CGBitmapContextCreateImage(conPattern); 

    UIImage *imgPattern = [[UIImage alloc]initWithCGImage:cgImage]; 
    //UIImageWriteToSavedPhotosAlbum(imgPattern, nil, nil, nil); Uncomment if you need to view textures (photo album). 

    self.standHeight = (top - bottom)*sceneScalar; 
    self.standWidth = (right - left)*sceneScalar; 
    self.xOffset = [startPoint.x floatValue]*sceneScalar; 
    self.yOffset = (-[startPoint.y floatValue]*sceneScalar)+standHeight; 

    CFRelease(cgImage); 
    CGContextRelease(conPattern); 

    return imgPattern; 

} 

Однако при попытке удалить текстуры следующим образом в viewWillDisappear, я вижу (в документах), что память не освобождается:

for (PolygonObject * stand in standArray) { 
      GLuint name = stand.textureInfo.name; 
      // delete texture from opengl 
      glDeleteTextures(1, &name); 
      // set texture info to nil 
      stand.textureInfo = nil; 
     } 

Я думаю, что что-то сохраняется в текстуре где-то в коде выше. Может ли кто-нибудь предложить, где?

+0

проверить ваш CTFramesetterRef освобождение с помощью [this] (http://stackoverflow.com/questions/11979283/how-to-release-a-ctframesetter) ответ – SAKrisT

+1

выглядит как проблема не в OpenGL, попробуйте просто создать образ и удалить, затем , без создания текстуры. И замените на - [UIImage imageWithCGImage:] – SAKrisT

ответ

0

Насколько я вижу, в вашем коде отсутствует утечка памяти, если вы используете ARC. Тем не менее, UIImage, возвращенный из drawTexture, может быть сохранен некоторыми другими объектами или пулом автоматического выпуска.

Чтобы проверить это, вы можете подклассифицировать UIImage, например UIDebugImage, переопределить метод dealloc и установить там контрольную точку, чтобы увидеть, вызвана ли она.