addSubview Memory Leak

Discussion in 'iPhone/iPad Programming' started by Sui Jen, Oct 29, 2009.

  1. macrumors newbie

    Joined:
    Oct 14, 2009
    #1
    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];
    }
     

Share This Page