【发布时间】:2012-08-29 07:28:40
【问题描述】:
在以下情况下使用CGMutablePath 时出现内存泄漏:
- (CGMutablePathRef) textMutablePathForFrame:(CGRect)frame
{
CGAffineTransform transform = CGAffineTransformMakeScale(frame.size.width / self.shapeMutablePathSize.width, frame.size.height / self.shapeMutablePathSize.height);
return CGPathCreateMutableCopyByTransformingPath(self.shapeMutablePath, &transform);
}
- (CTFrameRef) textFrameForFrame:(CGRect)frame framesetter:(CTFramesetterRef)framesetter
{
CGMutablePathRef textMutablePath = [self textMutablePathForFrame:frame];
CTFrameRef textFrame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, 0), textMutablePath, NULL);
CGPathRelease(textMutablePath);
return textFrame;
}
通过仪器分析,我在textMutablePathForFrame 中带有“return”的行出现内存泄漏,上面写着“在第 132 行分配的对象的潜在泄漏”(第 132 行是返回行本身)。
我还在textFrameForFrame 中的“CGPathRelease(textMutablePath);”行中发现内存泄漏:“调用者此时不拥有的对象的引用计数递减不正确”。
对此我无法理解,感觉我终于对 Core 中的内存管理有了一个很好的理解。
更新:看起来这可能是一个错误,将再次碰撞它,看看其他人是否有不同的感觉。
【问题讨论】:
-
你
CFRelease()调用函数返回的对象吗? -
@H2CO3 - 是的,我刚刚检查过,在所有情况下,当我调用 textMutablePathForFrame 时,我通常将它存储在本地 CTFrontRef 中,然后我为该本地 CTFontRef 设置一个属性,然后我释放本地CTFontRef.
-
@H2CO3 - 认为这可能是一个错误?
-
@H2CO3 - 感谢您的意见。
-
注意下面的评论。分析仪是正确的;这不是错误。名称应为
newMutablePathForFrame。
标签: iphone ios cocoa-touch core-graphics