发布 iVar IBOutlet 与 Property IBOutlet
谁能验证我的 dealloc 方法是否正确?由于我的 titleLabel 和 checkImageView 被保留,我将在 dealloc 中释放它们。但是,我不会释放 mainImageView、doneButton 和 noteLabel,因为它们在实现过程中不会被保留或分配。
@interface CheckMarkController : UIViewController <UIAlertViewDelegate> {
IBOutlet UIImageView *mainImageView;
IBOutlet UIButton *doneButton;
IBOutlet UILabel *noteLabel;
}
@property (nonatomic, retain) IBOutlet UILabel *titleLabel;
@property (nonatomic, retain) IBOutlet UIImageView *checkImageView;
@property (nonatomic, retain) Event *event;
@property (nonatomic, retain) Workout *workout;
@property (nonatomic, retain) NSManagedObjectContext *managedObjectContext;
@end
- (void)dealloc {
//props
[titleLabel release];
[checkImageView release];
[event release];
[workout release];
[managedObjectContext release];
[super dealloc];
Can anyone verify my dealloc method is correct? Since my titleLabel and checkImageView are retained I am releasing them in dealloc. However, I am not releasing mainImageView, doneButton, and noteLabel, because they are not retained or alloced during the implementation.
@interface CheckMarkController : UIViewController <UIAlertViewDelegate> {
IBOutlet UIImageView *mainImageView;
IBOutlet UIButton *doneButton;
IBOutlet UILabel *noteLabel;
}
@property (nonatomic, retain) IBOutlet UILabel *titleLabel;
@property (nonatomic, retain) IBOutlet UIImageView *checkImageView;
@property (nonatomic, retain) Event *event;
@property (nonatomic, retain) Workout *workout;
@property (nonatomic, retain) NSManagedObjectContext *managedObjectContext;
@end
- (void)dealloc {
//props
[titleLabel release];
[checkImageView release];
[event release];
[workout release];
[managedObjectContext release];
[super dealloc];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您通过 Interface Builder 连接这三个项目,则需要释放它们。默认保留插座。 KVC(Key Value Coding)用于设置插座。这意味着
loadFromNib
将为您设置的每个插座调用setValue:withKey
。这使用 @property 及其 setter 方法,但如果没有设置(如您的情况),它默认保留该对象。If you connect these three items via Interface Builder you DO need to release them. Outlets are retained by default. KVC (Key Value Coding) is used to set outlets. This means that
loadFromNib
will callsetValue:withKey
for each outlet you have set. This uses the@property
and it's setter method, but if none are set (as is your case) it retains the object by default.