Ben*_*Ben 5 iphone fonts objective-c core-text ios
我正在编写一个使用自定义字体(CTFontManagerRegisterFontsForURL)的IOS程序。我加载字体,将其添加为字符串属性,创建框架设定器,然后创建框架,并将其绘制到上下文中。我释放我使用的所有东西。仪器没有发现泄漏,但:
使用此功能时,应用程序使用的内存会增加而不会减少。离开功能时,字体的保留计数为2。
这是代码:
CFMutableAttributedStringRef attributedStringRef = CFAttributedStringCreateMutable(kCFAllocatorDefault, 0);
CFAttributedStringBeginEditing(attributedStringRef);
CFAttributedStringReplaceString(attributedStringRef, CFRangeMake(0, 0), (CFStringRef)label.text);
font = CTFontCreateWithName((CFStringRef)label.fontName, label.fontHeight, NULL);
Run Code Online (Sandbox Code Playgroud)
保留字体数:1
CFAttributedStringSetAttribute(attributedStringRef, CFRangeMake(0, label.text.length), kCTFontAttributeName, font);
CFAttributedStringEndEditing(attributedStringRef);
Run Code Online (Sandbox Code Playgroud)
保留字体数:2
CGMutablePathRef path = CGPathCreateMutable();
CGPathAddRect(path, NULL, rect);
CFRelease(font);
Run Code Online (Sandbox Code Playgroud)
保留字体数:1
CTFramesetterRef frameSetter = CTFramesetterCreateWithAttributedString(attributedStringRef);
Run Code Online (Sandbox Code Playgroud)
保留字体数:3
CFRelease(attributedStringRef);
CTFrameRef frame = CTFramesetterCreateFrame(frameSetter,
CFRangeMake(0, 0),
path, NULL);
Run Code Online (Sandbox Code Playgroud)
保留字体数:5
CFRelease(frameSetter);
Run Code Online (Sandbox Code Playgroud)
保留字体数:4
CTFrameDraw(frame, ctx);
CFRelease(frame);
Run Code Online (Sandbox Code Playgroud)
保留字体数:2
CGPathRelease(path);
Run Code Online (Sandbox Code Playgroud)
是否有某种缓存?我真的需要立即清除此字体使用的内存。
PS:我使用CFGetRetainCount来获取字体的保留计数。
谢谢 !