Search code examples
objective-ciosmemory-leakscore-textobjective-c-category

Core Text leak in category


I found a category for NSAttributedString they returns the height of the rectangle that contains the attributed string itself for a given width. Unfortunately Instruments says that there is a leak in that. Can you please tell me where it is?

@interface NSAttributedString (Height)
    - (CGFloat)boundingHeightForWidth:(CGFloat)inWidth;
@end

@implementation NSAttributedString (Height)

- (CGFloat)boundingHeightForWidth:(CGFloat)inWidth
{
    CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFMutableAttributedStringRef)self); 
    CGSize suggestedSize = CTFramesetterSuggestFrameSizeWithConstraints(framesetter, CFRangeMake(0, 0), NULL, CGSizeMake(inWidth, CGFLOAT_MAX), NULL);
    CFRelease(framesetter);
    return suggestedSize.height ;
}
@end

Solution

  • Sometimes static analysis and Instruments can report false positives for leaks. From looking at your category, it doesn't seem like there should be any leaks in there so i'd assume you can ignore this.