PDA

View Full Version : addSubview Memory Leak




Sui Jen
Oct 29, 2009, 03:48 AM
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!!

@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];
}