gpt4 book ai didi

iOS内存管理属性

转载 作者:行者123 更新时间:2023-11-29 01:39:37 24 4
gpt4 key购买 nike

这是一个MRC项目,是否存在过度发布的问题?因为属性 welcomeLabel 尚未被调用,所以我只使用了变量 _welcomeLabel

代码如下:

@interface MyViewController ()

@property (nonatomic, retain) UILabel *welcomeLabel;

@end

@implementation

- (void)dealloc {

[_welcomeLabel release];

[super dealloc];

}

- (void)viewDidLoad {

_welcomeLabel = [[[UILabel alloc] initWithFrame:CGRectMake(10, 10, 60, 40)] autorelease];

[self.view addSubView:_welcomeLabel];

}

@end

最佳答案

是的,因为您不使用属性 setter ,所以引用计数不会增加。 refcount 将保持为 1,你释放它两次,一次是在自动释放池耗尽时,一次是在 dealloc 中。

关于iOS内存管理属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32560684/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com