Я использую следующий метод для рисования текста в PDF-документе (контексте). Как-то инструменты придумывает следующую строку протечкиУтечка памяти в CFAttributedStringRef
CFAttributedStringRef currentText = CFAttributedStringCreate(NULL, stringRef, NULL);
Где я выпустить stringRef. Вот код (После правильных ответов здесь обновленное/рабочий код):
- (void)drawText:(NSString*)textToDraw inFrame:(CGRect)frameRect{
CFStringRef stringRef = (__bridge CFStringRef)textToDraw;
// Prepare the text using a Core Text Framesetter
CFAttributedStringRef currentText = CFAttributedStringCreate(NULL, stringRef, NULL);
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(currentText);
CGMutablePathRef framePath = CGPathCreateMutable();
CGPathAddRect(framePath, NULL, frameRect);
// Get the frame that will do the rendering.
CFRange currentRange = CFRangeMake(0, 0);
CTFrameRef frameRef = CTFramesetterCreateFrame(framesetter, currentRange, framePath, NULL);
CGPathRelease(framePath);
// Get the graphics context.
CGContextRef currentContext = UIGraphicsGetCurrentContext();
// Put the text matrix into a known state. This ensures
// that no old scaling factors are left in place.
CGContextSetTextMatrix(currentContext, CGAffineTransformIdentity);
// Core Text draws from the bottom-left corner up, so flip
// the current transform prior to drawing.
CGContextTranslateCTM(currentContext, 0, frameRect.origin.y*2);
CGContextScaleCTM(currentContext, 1.0, -1.0);
// Draw the frame.
CTFrameDraw(frameRef, currentContext);
CGContextScaleCTM(currentContext, 1.0, -1.0);
CGContextTranslateCTM(currentContext, 0, (-1)*frameRect.origin.y*2);
CFRelease(frameRef);
//CFRelease(stringRef); The string shouldn't be released
CFRelease(framesetter);
//Added the next line:
CFRelease(currentText);
}
протестировали его на устройстве в качестве тренажера; он течет
Спасибо за быстрый ответ. Когда я добавляю CFRelease (currentText), мое приложение вылетает .. mmm – Oritm
вы можете отправить сообщение об ошибке? Скорее всего, это вы, когда к нему обращается что-то другое (например, framesetter). –
он просто падает, но когда у меня включен NSZombies, он приходит с: *** - [CFString release]: сообщение отправлено на освобожденный экземпляр 0xf6534c0 – Oritm