Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Sui Jen

macrumors newbie
Original poster
Oct 14, 2009
13
0
Hi,

There is a memory leak in the following code. The memory leak occurs after I add the line “[self.view addSubview:mobileField];”. I release mobileField in the method (void)dealloc. May I know what is wrong with my code?

Thanks a lot!!

Code:
@interface SetupController : UIViewController <UITextFieldDelegate, UIAlertViewDelegate>{
	UITextField *mobileField;

}

@property (nonatomic, retain) IBOutlet UITextField *mobileField;

@end

- (void)viewDidLoad {
	
	self.title = @"Setup";
		
	CGRect frameb = CGRectMake(115.0, 55.0, 175.0, 31.0);
	UITextField *mobField = [[UITextField alloc] initWithFrame:frameb];
    self.mobileField = mobField;
    

    mobileField.textAlignment = UITextAlignmentLeft;
    mobileField.borderStyle = UITextBorderStyleRoundedRect;
    mobileField.keyboardType = UIKeyboardTypeDefault;
    mobileField.returnKeyType = UIReturnKeyDone;
	mobileField.delegate = self;
    [self.view addSubview:mobileField];

	[mobField release];
	
	
}

- (void)dealloc {

	[mobileField release];
	[super dealloc];
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.