1

我在我的应用程序中使用 CoreText,我有一个非常大的泄漏,但我无法找出它发生的原因。所以这是我的代码片段:

 _framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)_mAttributedString);

CFDictionaryRef frameOptionsDictionary = (CFDictionaryRef)[self frameOptionsDictionary];

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

CFRelease(_framesetter), _framesetter = NULL;

正如你所看到的,我正在释放我 CTFramesetter ......但是应用程序泄漏,并且仪器向我显示 CTFramesetter 导致了这种情况。那么我应该如何释放它呢?

4

1 回答 1

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;
于 2012-08-16T04:37:32.683 回答