【发布时间】:2012-01-19 11:33:17
【问题描述】:
我正在编写一个使用自定义字体 (CTFontManagerRegisterFontsForURL) 的 IOS 程序。我加载字体,将其添加为字符串属性,创建框架设置器,然后创建框架,并将其绘制到上下文中。 我释放我使用的一切。 Instruments 没有注意到泄漏,但是:
使用此功能时,应用程序使用的内存会增长,不会缩小。 当我离开函数时,我的字体的保留计数是 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 来获取字体的保留计数。
谢谢!
【问题讨论】:
标签: iphone objective-c ios fonts core-text