来自 CTFramesetterCreateWithAttributedString 的 CoreText 内存泄漏 [英] CoreText memory leak from CTFramesetterCreateWithAttributedString

查看:47
本文介绍了来自 CTFramesetterCreateWithAttributedString 的 CoreText 内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个有问题的泄漏——多亏了 Instruments——它似乎来自 CTFrameSetterCreateWithAttributedString.调用堆栈在下面.

I'm coming across a problematic leak which - thanks to Instruments - appears to be coming from CTFrameSetterCreateWithAttributedString. The call stack is below.

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

生成这个调用栈的代码是:

The code generating this call stack is:

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

self.attributedString 在别处被释放.我觉得我正在正确地发布其他所有内容......考虑到所有这些,泄漏可能来自哪里?这对我的目的来说相当重要 - 一次 6-10 MB.感谢您的帮助.

self.attributedString gets released elsewhere. I feel like I'm correctly releasing everything else... Given all this, where could the leak be coming from? It's fairly significant for my purposes - 6-10 MB a pop. Thanks for any help.

推荐答案

事实证明,通过不对 CFMutableArrayRef 使用 ivar,这个问题得到了实质性的解决.我们为 CoreText 使用了 Akosma Obj-C 包装器,在 AKOMultiColumnTextView 类中有一个 CFMutableArrayRef _frames ivar,出于某种原因,它甚至在 CFRelease 调用之后仍然存在.没有 _frames ivar 有点贵,但显着改善了内存使用.感谢 Neevek 的贡献.

Turns out this problem was substantially addressed by not using an ivar for a CFMutableArrayRef. We were using the Akosma Obj-C wrapper for CoreText, and in the AKOMultiColumnTextView class there's a CFMutableArrayRef _frames ivar which - for some reason - is hanging around even after CFRelease calls. Not having the _frames ivar is a bit expensive, but has drastically improved memory usage. Thanks Neevek for your contributions.

这篇关于来自 CTFramesetterCreateWithAttributedString 的 CoreText 内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆