如何发布CTFramesetter?

时间:2012-08-16 00:52:23

标签: objective-c ios core-graphics core-text

我在我的应用程序中使用CoreText并且我有一个非常大的泄漏,但我不知道它为什么会发生。所以这是我的代码的片段:

 _framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)_mAttributedString);

CFDictionaryRef frameOptionsDictionary = (CFDictionaryRef)[self frameOptionsDictionary];

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

CFRelease(_framesetter), _framesetter = NULL;

正如你所看到的,我正在向我发布CTFramesetter ......但app泄漏了,仪器告诉我CTFramesetter会导致这种情况。那我该怎么发布呢?

1 个答案:

答案 0 :(得分:0)

0)确保没有失败:

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;