How to release a CTFramesetter?

不问归期 提交于 2019-12-24 11:12:01

问题


I am using CoreText in my app and i have a really huge leak but i cant fnd out why it happens. so here is the snippet of my code:

 _framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)_mAttributedString);

CFDictionaryRef frameOptionsDictionary = (CFDictionaryRef)[self frameOptionsDictionary];

_frame = CTFramesetterCreateFrame(_framesetter,
                                CFRangeMake(0, _mAttributedString.length),
                                path,
                                frameOptionsDictionary);

CFRelease(_framesetter), _framesetter = NULL;

As you can see, i am releasing me CTFramesetter... but app leaks, and instruments show me that CTFramesetter causes that. So how should i release it?


回答1:


0) ensure there are no failures:

assert(_mAttributedString);
assert(0 == _framesetter);
_framesetter = CTFramesetterCreateWithAttributedString(
                             (CFAttributedStringRef)_mAttributedString);

CFDictionaryRef frameOptionsDictionary =
                   (CFDictionaryRef)[self frameOptionsDictionary];

assert(path);
assert(0 == _frame);
_frame = CTFramesetterCreateFrame(_framesetter,
                                CFRangeMake(0, _mAttributedString.length),
                                path,
                                frameOptionsDictionary);

CFRelease(_framesetter), _framesetter = NULL;


来源:https://stackoverflow.com/questions/11979283/how-to-release-a-ctframesetter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!