【问题标题】:iOS Analyze - Assuming "self" is non-nilliOS 分析 - 假设“自我”不是零
【发布时间】:2015-05-13 13:14:31
【问题描述】:

我正在分析我的应用程序并遇到以下错误。有人可以帮帮我吗?

- (id)initWithLayer:(id)layer
{
    self = [super initWithLayer:layer];

    if (self)
    {
        [self setDefaults];

        MCNewCustomLayer *other = (MCNewCustomLayer*)layer;
        self.value              = other.value;
        self.textLabel          = other.textLabel;
        self.selectionStatus    = other.selectionStatus;
        self.animationDuration  = other.animationDuration;
        self.mainPath           = CGPathCreateMutableCopy(other.mainPath);
        self.fillColor          = CGColorCreateCopy(other.fillColor);
        self.strokeColor        = CGColorCreateCopy(other.strokeColor);
        self.mainPathImage      = other.mainPathImage;
        self.identifier         = other.identifier;
        self.parentLayeredView  = other.parentLayeredView;
        self.isAllowedToAnimate = other.isAllowedToAnimate;
        self.imageBoundsStyle   = other.imageBoundsStyle;

        self.isPresentationLayer  = YES;

    }

    return self;


}

警告信息是这样的:

假设 'self' 不为零

调用函数 'CGPathCreateMutableCopy' 会返回一个具有 +1 保留计数的 Core Foundation 对象

对象泄露:分配的对象在此执行路径的后面没有被引用,并且保留计数为 +1

【问题讨论】:

标签: ios objective-c


【解决方案1】:

您想调用CGPathRelease(other.mainPath); 来释放保留计数,这样您就不会发生内存泄漏。

【讨论】:

  • 我必须在哪里添加它?
猜你喜欢
  • 1970-01-01
  • 2021-07-13
  • 2018-06-10
  • 1970-01-01
  • 2020-07-01
  • 2021-01-11
  • 1970-01-01
  • 2017-06-21
  • 2016-02-04
相关资源
最近更新 更多