addSubview Memory Leak

Discussion in 'iOS Programming' started by Sui Jen, Oct 29, 2009.

  1. macrumors newbie

    Oct 14, 2009

    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;
    - (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];

Share This Page