我必须“释放”吗?我声明为 IBOutlets 且属性属性为“retain”的 UI 对象和“非原子”?
我是否必须“释放”我声明为 IBOutlet 且属性属性为“保留”和“非原子”的 UI 对象?我问这个问题是因为我有一个 UI var 声明为如此...
@interface MyViewController : UIViewController
{
IBOutlet UILabel *lblStatus;
}
@property (retain, nonatomic) IBOutlet UILabel *lblStatus;
@end
并且我的 dealloc 如此...
- (void)dealloc
{
//[lblStatus release];
[super dealloc];
}
并且将 lblStatus
UI var 注释掉,当我弹出时,Instruments 似乎没有检测到任何泄漏导航堆栈之外的视图。
预先感谢您的帮助!
Do I have to "release" my UI objects that I declared as IBOutlets with property attributes "retain" and "nonatomic"? I ask because I have a UI var declared as so...
@interface MyViewController : UIViewController
{
IBOutlet UILabel *lblStatus;
}
@property (retain, nonatomic) IBOutlet UILabel *lblStatus;
@end
and my dealloc like so...
- (void)dealloc
{
//[lblStatus release];
[super dealloc];
}
and with the lblStatus
UI var commented out, Instruments doesn't seem to detect any leaks when I pop the view off the navigation stack.
Thanks in advance for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
既然它们被保留了,是的,你有责任释放它们。通常,对于视图控制器,这应该发生在
-viewDidUnload
中,如下所示:(使用合成的
retain
访问器设置属性的值,将在设置属性之前释放旧值实例变量为新值。)Since they're retained, yes, you are responsible for releasing them. Usually, with view controllers, that should happen in
-viewDidUnload
, like so:(Setting the property's value, with a synthesized
retain
accessor, will release the old value before setting the instance variable to the new value.)