I have a problem removing my OpenGL ES textures created using Quartz 2D and Core Text, as shown below:
- (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];
However, when I try to remove textures as follows in viewWillDisappear, I see (in tools) that the memory is not freed:
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; }
I think something is stored in the texture somewhere in the code above. Can anyone suggest where?
objective-c automatic-ref-counting core-graphics core-text quartz-2d
GuybrushThreepwood
source share