I found a somewhat related question at iPhone - dealloc - Release vs. nil, but it didn't answer my question.
I created a button, a UIScrollview
, and a label inside of it in the storyboard. When I Ctrl-dragged the objects to ViewController.h they created this:
@interface ViewController : UIViewController{
__weak IBOutlet UIScrollView *scroller;
}
@property (weak, nonatomic) IBOutlet UIButton *goButton;
@property (weak, nonatomic) IBOutlet UILabel *label;
@property (weak, nonatomic) IBOutlet UIScrollView *scroller;
- (IBAction)pressGo:(id)sender;
@end
And at the top of ViewController.m I have:
@implementation ViewController
@synthesize goButton;
@synthesize label;
@synthesize scroller;
And in viewDidUnload
it created:
[self setGoButton:nil];
[self setScroller:nil];
[self setLabel:nil];
scroller = nil;
[super viewDidUnload];
All created automatically. I've seen many references to dealloc
and release
.
Will this code, the premade stuff, prevent memory leaks? Or must I add dealloc
?
I apologize for any errors I have made... I'm new to this.
If IBOutlet are marked as weak, there's no need of setting them to nil in viewDidLoad. If you are compiling with ARC there's also no need of writing dealloc, in any case the compiler itself is going to give you error if you write any dealloc or release statement.
With Xcode 4 ARC being default option, if you make sure of that your code is memory safe.