【问题标题】:UIBezierPath bezierPathWithRect memory leakUIBezierPath bezierPathWithRect 内存泄漏
【发布时间】:2014-11-17 09:12:50
【问题描述】:

我正在对我的应用程序执行一些分析。我有一个计算 CGRect 并基于此返回 UIBezierPath 的方法。

XCode Instruments 中的Leaks 工具正在使用UIBezierPath bezierPathWithRect: 方法显示内存泄漏。有没有其他人遇到过这种问题?有没有可能是误报?

我在 iPhone 5s 和 iPhone 5c 上都进行了测试,结果是一样的。下面是我Instruments的一些截图(图1是泄漏方法的线路描述,图2是仪器捕捉到的泄漏,都导致了这种方法):

编辑:代码摘录

- (UIBezierPath *)boundaryPath {
  CGRect boundary = CGRectZero;
UIBezierPath *bezierPath;
boundary.size.width = CGRectGetWidth(self.paneView.frame)/2;
boundary.size.height = CGRectGetHeight(self.tightWindow.frame);

if (CGRectGetMinX(self.tightWindow.frame) > 0) {
boundary.origin.x = 0.0f;
boundary.origin.y = 0.0f;
} else {
boundary.origin.x = CGRectGetMinX(self.paneView.frame);
boundary.origin.y = CGRectGetMinY(self.paneView.frame);
}

bezierPath = [UIBezierPath bezierPathWithRect:boundary];

return bezierPath;
}

编辑 2 - 方法使用

@property (nonatomic, strong) UICollisionBehavior *paneBoundaryCollisionBehavior;

...

[self.paneBoundaryCollisionBehavior removeAllBoundaries];
[self.paneBoundaryCollisionBehavior addBoundaryWithIdentifier:identifier forPath:[self boundaryPath]];

【问题讨论】:

  • 请发布您的代码。
  • 能否请教其他相关代码(如该方法的用法)?

标签: ios iphone memory-leaks


【解决方案1】:

你能描述一下代码吗? 好吧,就我而言,我遇到了返回CGPath 之类的问题。返回的值是一个CGPathRef,它没有被ARC 覆盖。您创建的UIBezierPath 在方法结束后被释放。因此也释放了CGPathRef。您可以指定源注释以让 ARC 知道您的意图:

在.h文件中:

-(CGPathRef)makeToPath CF_RETURNS_RETAINED;
-(CGPathRef)makeFromPath CF_RETURNS_RETAINED;

希望有帮助!!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-08
    • 2013-01-20
    • 2011-10-31
    • 2019-08-10
    • 2013-06-24
    相关资源
    最近更新 更多