views:

94

answers:

1

If I have something like this in my .h file:

@property (nonatomic,retain) IBOutlet UIButton *btnHelp;

Should I release it in the dealloc function of the .m file?

+3  A: 

If you indeed meant for this property to be read-write, then the answer is yes -- dealloc has to release btnHelp. In your code, the property is annotated with 'retain'. This means that every time a user of your class sets the btnHelp property, your class sends a 'retain' message to the new property value -- making your class responsible for also sending a 'release' message when it's done. If you create btnHelp in the class initialization code, make sure you retain it there too.

If, however, you only mean to provide read-only access to a button that was loaded from a NIB file, you do not need to worry about releasing it -- it's the responsibility of the object that loaded the nib. In that case, replace 'retain' with 'readonly'.

Oren Trutner