views:

359

answers:

5

Hi, In my code, there is an memory leak, when the Keyboard appears for the first time when I am about to enter values in the UITextField. Can someone please give me some idea about this.

In the Interface File

IBOutlet UITextField *userEmail; 

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

Implementation File

@synthesize userEmail; 

- (void)dealloc 
{ 
  [userEmail release]; 
} 

- (void)viewDidUnload 
{ 
  self.userEmail = nil; 
} 

-(IBAction) emailOver:(id)sender{ 
  [sender resignFirstResponder]; 
}

In the one of the functions NSLog(@"User Email: %@",[userEmail text]); Memory Leak occurs when the keyboard appears for the first time Do I have implement UITextFieldDelegate? Thanks

A: 

You don't need IBOutlet defined twice. One or the other should do.

UITextField *userEmail; 

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

I don't see anything else in your code that would cause a problem. What other methods do you have in your @implementation file.

Jordan
A: 

One problem is that your dealloc method is missing the MANDATORY [super dealloc] line.

- (void)dealloc 
{ 
  [userEmail release];
  [super dealloc]; 
}
Amagrammer
A: 

John, Have you solved this? I have the identical problem. Can you update us? Perhaps show us the stack trace for the leak? -VTPete

VTPete
+1  A: 

Consider that there's a bug in the iPhone simulator: if you write an almost empty project, putting only a UITextField in the XIB, and no code, you'll have a leak when you tap on the UITextField. On the contrary, if you try to build and run on the device, you'll have no leak. So It may be your case!! Give it a try, and let us know..

caprosky
A: 

I think you're right caprosky. Using a very simple test project I've Run With Monitoring Tools -> Leaks and as soon as I click on UITextField there is a memory leak that rises continuously.

I'll forget this for now and keep it in mind next time I'm using a UITextField (no

Gaz Newt