我有一个自定义的UITableViewCell,暂且叫ACell,该cell有以下属性:
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIButton *deleteButton;
全部addSubview到cell的contentView,主要是点击deleteButton之后把titleLabel移除:
- (void)deleteButtonClicked {
[self.titleLabel removeFromSuperview];
}
执行以上语句之后我发现,titleLabel还是存在于内存中。就像下面这样:
怎么样才能让它立即销毁
The reason is: ACell still holds the titleLabel object.
Solution:
self.titleLabel = nil;
Replace strong with weak. One thing to note is to copy the attributes after addsubview