【发布时间】:2011-07-04 00:21:05
【问题描述】:
我有一个代码:
@interface PhotoListViewController : UIViewController
{
IBOutlet UIImageView* firstPicContainer;
IBOutlet UIImageView* secondPicContainer;
UIImage* pic_one;
UIImage* pic_two;
IBOutlet UILabel* firstPicLabel;
IBOutlet UILabel* secondPicLabel;
NSString* firstPicName;
NSString* secondPicName;
IBOutlet UILabel* authorLabelA;
IBOutlet UILabel* authorLabelB;
NSString* authorName;
}
@property (retain) UIImage* pic_one;
@property (retain) UIImage* pic_two;
@property (copy) NSString* firstPicName;
@property (copy) NSString* secondPicName;
@property (copy) NSString* authorName;
@end
问题是:我应该释放整个对象包还是只释放那些我已声明其属性的对象? 例如:firstPicName为NSString并被保留,设置时其容器为UILabel* firstPicLabel,赋值如下:
firstPicLabel.text = firstPicName;
在 -viewDidLoad 中。所以标签作为一个对象不会被自己保留,它的属性会。其他对象也是如此,保留属性,其他只是一个容器。这些容器的所有者是他们的观点,应该对它们的释放负责,但我在这里有点困惑,所以我想澄清这一点。 谢谢。
【问题讨论】:
-
请不要在 ivar 名称或方法名称中使用下划线;与常规相比,它看起来格格不入。
标签: objective-c ios memory-management dealloc