搜尋

首頁  >  問答  >  主體

objective-c - iOS中UIView调用removeFromSuperView之后没有释放内存

我有一个自定义的UITableViewCell,暂且叫ACell,该cell有以下属性:

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIButton *deleteButton;

全部addSubview到cell的contentView,主要是点击deleteButton之后把titleLabel移除:

- (void)deleteButtonClicked {
    [self.titleLabel removeFromSuperview];
}

执行以上语句之后我发现,titleLabel还是存在于内存中。就像下面这样:

怎么样才能让它立即销毁

伊谢尔伦伊谢尔伦2852 天前1126

全部回覆(2)我來回復

  • 黄舟

    黄舟2017-04-18 09:42:45

    原因是:ACell 依然持有 titleLabel 物件。
    解決方法:self.titleLabel = nil;

    回覆
    0
  • ringa_lee

    ringa_lee2017-04-18 09:42:45

    把strong換成weak,注意一點就是,在addsubview 之後再給屬性複製

    回覆
    0
  • 取消回覆