I'm aware best practices for Objective-C development says IBOutlets should always be defined as properties according to Apple.
From a practical perspective, in iOS and OS X outlets should be defined as declared properties. Outlets should generally be weak, except for those from File’s Owner to top-level objects in a nib file (or, in iOS, a storyboard scene) which should be strong.
But for learning purposes let's say we got the following scenario using ARC:
#import <UIKit/UIKit.h>
@interface DetailViewController : UIViewController{
IBOutlet UIButton *buttonA;
IBOutlet UIButton *buttonB;
IBOutlet UIButton *buttonC;
}
@end
If I'm not mistaken, those three buttons are strong, so my question is: Will those buttons be released from memory once the ViewController is released?
Those buttons would be released automatically if they were weak, I know that, but not sure if they are strong.
Can anyone please help? Just to be clear, the method 'dealloc' on DetailViewController is empty.
viewDidUnload
. And call[super viewDidUnload]
after that. But better way is to make@interface DetailViewController ()
in@implementation
and there create properties for outlets. – Tomasz SzulcviewDidUnload
is not called anymore; and (b) even when it was used, its sole purpose was handling the unloading of some views when memory warnings were received. So, handleviewDidUnload
if you need backward compatibility and are worried about this special scenario in pre-ARC code usingretain
with itsIBOutlet
references. But when considering the basic object graph,viewDidUnload
is not relevant. – Robnil
-ing of them is needed. (It's one of the joys of ARC.) In non-ARC code, you have to write your owndealloc
method that manually performsrelease
for all of those strong variables. – Rob