UILabel(CALayer)在ARC漏水?

时间:2013-12-02 12:27:29

标签: objective-c memory-management uilabel automatic-ref-counting instruments

我陷入了问题,几天后检查了很多答案。我的问题是,当我在Xcode中选择配置文件> Leaks时,我看到UILabel(CALayer)在Live Bytes中总是越来越大。它是正常还是泄漏?我该怎么办呢?当我改变课程并返回具有这些标签的班级时,它会变得越来越大。就像他们一遍又一遍地分配而不是释放旧的那样。

我将标签设置为h。这样的文件

@property(weak,nonatomic)IBOutlet UILabel *lblNumbersSpelling1;
@property(weak,nonatomic)IBOutlet UILabel *lblNumbersSpelling2;
@property(weak,nonatomic)IBOutlet UILabel *lblNumbersSpelling3;
@property(weak,nonatomic)IBOutlet UILabel *lblNumbersSpelling4;

和,

- (void)viewDidUnload
{
    [super viewDidUnload];

    self.lblNumbersSpelling1=nil;
    self.lblNumbersSpelling2=nil;
    self.lblNumbersSpelling3=nil;
    self.lblNumbersSpelling4=nil;
    self.lblRecordSayfasiNot=nil;
   // Release any retained subviews of the main view.
}

我这样做了,我不确定我是否有必要在viewDidUnload方法中做什么。 我使用Xcode 5。 提前谢谢。

2 个答案:

答案 0 :(得分:2)

viewDidUnloaddeprecated in iOS6 and later

可能你想要这样做:

- (void)dealloc
{
    _lblNumbersSpelling1=nil;
    _lblNumbersSpelling2=nil;
    _lblNumbersSpelling3=nil;
    _lblNumbersSpelling4=nil;
    _lblRecordSayfasiNot=nil;
}

答案 1 :(得分:2)

我的UILabel(CALayer)应用程序在Xcode的配置文件工具中的内存使用量增加时遇到了同样的问题。在一天结束时,内存增加的UILabel(CALayer)最终成为另一个问题引起的内存泄漏的症状(特别是对代表的强烈引用)。

我会检查以下内容,以确保另一个问题不会导致UILabel(CALayer)被保留:

  1. 使任何NSTimers无效
  2. 删除所有观察者到NSNotificationCenter
  3. 确保您使用块中的自我弱引用
  4. 确保所有委托属性都使用弱引用
  5. 来源:http://www.reigndesign.com/blog/debugging-retain-cycles-in-objective-c-four-likely-culprits/