Saturday, July 21, 2012

Are your Nib objects leaking memory?

Well, here are the 5 steps to correctly manage memory of nib objects.

Step 1: Declare outlets using the declared properties feature in the header file.

@property (nonatomic, retain) IBOutlet UILabel *nameLabel;

Step 2: Set your outlets to nil in viewDidUnload

- (void)viewDidUnload {
     self.nameLabel = nil;
     [super viewDidUnload];
}

Step 3: Release your outlet in the dealloc method and set it to nil

- (void)dealloc {
      // Release outlets and set outlet variables to nil.
     [nameLabel release];
     nameLabel = nil;
     [super dealloc];
}

What you should remember
1. The call to [super dealloc] should be the last line in your dealloc function and the call to [super viewDidUnload] should be the last line in your viewDidUnload function

No comments:

Post a Comment