Note that there are some explanatory texts on larger screens.

plurals
  1. POMemory leak in CFAttributedStringRef
    primarykey
    data
    text
    <p>I use the following method to draw text on a PDF document (context). Somehow instruments comes up with the following line leaking</p> <pre><code>CFAttributedStringRef currentText = CFAttributedStringCreate(NULL, stringRef, NULL); </code></pre> <p>Where i am release the stringRef. Here's the code (After the correct answers here's the updated/working code):</p> <pre><code>- (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); </code></pre> <p>}</p> <p>Tested it on a device as the simulator; it leaks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload