I have a very classical class which contains buttons and label, etc... :
@interface ExerciseViewController : UIViewController {
// Hardcoding for outlets to XIB file
// Outlets can be passed only as singe variables in Interface Builder.
// Therefore, we can only declare stupid variables, not arrays of buttons.
// Bid array
// Labels S,W,开发者_如何学JAVAN,E
IBOutlet UILabel *labelSouth;
IBOutlet UILabel *labelWest;
IBOutlet UILabel *labelNorth;
IBOutlet UILabel *labelEast;
Of course, all those properties retain:
@property (nonatomic, retain) IBOutlet UILabel *labelSouth;
I just would like to know if I must release all those items in the dealloc method of my class:
- (void)dealloc {
[super dealloc];
// Release all GUI objects;
So, should I take all my properties and send a release to each of them? I tend to believe yes, but I prefer to ask.
Regards, Apple92
Yes, if you retain
you must release
If your class is retaining an object, you are taking responsibility for it and must release it later. That is the foundation of retain/release memory management.
See the Apple documentation on memory management rules.
It is my understanding that when working with objects from a XIB file, that the properties you are going to attach them to should be (nonatomic, assign), and you should NOT release them in the dealloc. The reason being that the XIB loading system takes care of memory management for objects it creates.
精彩评论