处理CGMutablePath时内存泄漏

时间:2012-08-29 07:28:41

标签: iphone ios cocoa-touch core-graphics

在以下情况下使用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;
}

通过仪器分析,我在return中的“textMutablePathForFrame”行显示“在第132行分配的对象的潜在泄漏”(第132行是返回行本身)的内存泄漏

我还在textFrameForFrame的“CGPathRelease(textMutablePath);”行中收到内存泄漏,其中说:“调用者此时不拥有的对象的引用计数的不正确减少”。

无法理解这一点,觉得我终于对Core中的内存管理有了很好的理解。

更新:看起来这可能是一个错误,再次碰到它,看看是否有其他人有不同的感受。

2 个答案:

答案 0 :(得分:2)

@JonathanCichon原则上是正确的,但具有错误的命名约定。 ObjC方法的正确命名约定是newMutablePathForFrame。分析仪是正确的。 “创建”规则仅适用于Core Foundation。 ObjC命名约定在Advanced Memory Management Programming Guide中。核心基础规则略有不同,包括“创建”规则,位于Memory Management Programming Guide for Core Foundation

答案 1 :(得分:1)

我不认为您有内存泄漏,将textMutablePathForFrame方法名称更改为createMutablePathForFrame,警告应该消失。

相关问题