2
\$\begingroup\$

When I want to make some quick tests for my UITableViewControllers, I usually create an NSArray that holds some dummy data. I would like to know if I'm doing anything wrong here:

First in MasterViewController.h:

#import <UIKit/UIKit.h>
@class DetailViewController;
@interface MasterViewController : UITableViewController
@property (nonatomic, retain) NSArray *dataSourceArray;
@end

and then in MasterViewController.m:

#import "MasterViewController.h"
@implementation MasterViewController
@synthesize dataSourceArray = _dataSourceArray;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
 self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
 if (self) {
 self.title = NSLocalizedString(@"Master", @"Master");
 _dataSourceArray = [[NSArray alloc] initWithObjects:@"obj 1", @"obj 2", @"obj 3", nil];
 }
 return self;
}
- (void)dealloc
{
 [_dataSourceArray release];
 [super dealloc];
}

So, the real question, as long as I'm not assigning _dataSourceArray to something else, I'm safe in terms of memory management here, right?

asked Feb 1, 2012 at 9:11
\$\endgroup\$
1
  • \$\begingroup\$ I agree, the code looks good to me. \$\endgroup\$ Commented Aug 17, 2012 at 13:28

1 Answer 1

1
\$\begingroup\$

Yes. Everything seems correct here.

Like you mention yourself: make sure you use self.dataSourceArray to assign new values, and the synthesized setter will take care of memory management.

answered Feb 1, 2012 at 10:55
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.