objective-c - iOS中UIView调用removeFromSuperView之后没有释放内存
伊谢尔伦
伊谢尔伦 2017-04-18 09:40:45
0
2
1077

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

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

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

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

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

怎么样才能让它立即销毁

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(2)
黄舟

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!