对于这段代码:
CTFontRef font = CTFontCreateWithName((__bridge CFStringRef)self.fontName, self.paragraphSpacing, NULL);
[self.text insertAttributedString: [[NSAttributedString alloc] initWithString: @" \n" attributes: [NSDictionary dictionaryWithObjectsAndKeys: (__bridge id)font, (id)kCTFontAttributeName, (id)[self paragraphStyle], (id)kCTParagraphStyleAttributeName, nil]] atIndex: 0];
[self.text appendAttributedString: [[NSAttributedString alloc] initWithString: @"\n " attributes: [NSDictionary dictionaryWithObjectsAndKeys: (__bridge id)font, (id)kCTFontAttributeName, (id)[self paragraphStyle], (id)kCTParagraphStyleAttributeName, nil]]];
CFRelease(font);
对于中间两行,我得到了“对象的潜在泄漏”,但我并没有真正看到问题所在。
我应该提到静态分析器指向的[self paragraphStyle]
是:
- (CTParagraphStyleRef) paragraphStyle
{
CTTextAlignment alignment = self.alignment;
CGFloat lineSpacing = self.lineSpacing;
CGFloat firstLineHeadIndent = self.indent;
CGFloat headIndent = self.indent;
CGFloat tailIndent = -self.indent;
CTParagraphStyleSetting paragraphSettings[] =
{
{kCTParagraphStyleSpecifierAlignment, sizeof(alignment), &alignment},
{kCTParagraphStyleSpecifierLineSpacing, sizeof(lineSpacing), &lineSpacing},
{kCTParagraphStyleSpecifierFirstLineHeadIndent, sizeof(firstLineHeadIndent), &firstLineHeadIndent},
{kCTParagraphStyleSpecifierHeadIndent, sizeof(headIndent), &headIndent},
{kCTParagraphStyleSpecifierTailIndent, sizeof(tailIndent), &tailIndent},
};
return CTParagraphStyleCreate(paragraphSettings, 5);
}