使用此函数时,应用程序使用的内存会增加,并且不会缩小。
当我离开该函数时,我的字体保留计数为2。
以下是代码:
CFMutableAttributedStringRef attributedStringRef = CFAttributedStringCreateMutable(kCFAllocatorDefault, 0);
CFAttributedStringBeginEditing(attributedStringRef);
CFAttributedStringReplaceString(attributedStringRef, CFRangeMake(0, 0), (CFStringRef)label.text);
font = CTFontCreateWithName((CFStringRef)label.fontName, label.fontHeight, NULL);
字体的保留计数为:1
CFAttributedStringSetAttribute(attributedStringRef, CFRangeMake(0, label.text.length), kCTFontAttributeName, font);
CFAttributedStringEndEditing(attributedStringRef);
字体的保留计数为2。
CGMutablePathRef path = CGPathCreateMutable();
CGPathAddRect(path, NULL, rect);
CFRelease(font);
字体的保留计数:1
CTFramesetterRef frameSetter = CTFramesetterCreateWithAttributedString(attributedStringRef);
字体的保留计数为:3
CFRelease(attributedStringRef);
CTFrameRef frame = CTFramesetterCreateFrame(frameSetter,
CFRangeMake(0, 0),
path, NULL);
字体的保留计数:5
CFRelease(frameSetter);
字体的保留计数为4。
CTFrameDraw(frame, ctx);
CFRelease(frame);
字体的保留计数: 2
CGPathRelease(path);
有一种缓存吗?我真的需要立即清除此字体使用的内存。
P.S:我使用CFGetRetainCount获取字体的保留计数。
谢谢!