CoreText内存从CTFramesetterCreateWithAttributedString泄漏

时间:2012-04-23 17:20:03

标签: memory-leaks core-text

我遇到了一个有问题的泄漏 - 感谢Instruments - 似乎来自CTFrameSetterCreateWithAttributedString。调用堆栈位于下方。

1 CoreText -[_CTNativeGlyphStorage prepareWithCapacity:preallocated:]
2 CoreText -[_CTNativeGlyphStorage initWithCount:]
3 CoreText +[_CTNativeGlyphStorage newWithCount:]
4 CoreText TTypesetterAttrString::Initialize(__CFAttributedString const*)
5 CoreText TTypesetterAttrString::TTypesetterAttrString(__CFAttributedString const*)
6 CoreText TFramesetterAttrString::TFramesetterAttrString(__CFAttributedString const*)
7 CoreText CTFramesetterCreateWithAttributedString

生成此调用堆栈的代码是:

CFAttributedStringRef attrRef = (CFAttributedStringRef)self.attributedString;
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(attrRef);
CFRelease(attrRef);
...
CFRelease(framesetter);

self.attributedString在其他地方发布。我觉得我正确地释放了其他一切......鉴于这一切,泄漏可能来自哪里?这对我的目的来说相当重要 - 一个流行音乐6-10 MB。谢谢你的帮助。

1 个答案:

答案 0 :(得分:0)

事实证明,对于CFMutableArrayRef,不使用ivar可以解决这个问题。我们使用了Akosma Obj-C包装器用于CoreText,而在AKOMultiColumnTextView类中有一个CFMutableArrayRef _frames ivar,由于某种原因,它甚至在CFRelease调用之后仍然存在。没有_frames ivar有点贵,但却大大提高了内存使用率。感谢Neevek的贡献。

相关问题