felix
felix

Reputation: 11552

UITextField Memory Leak

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

Upvotes: 1

Views: 2608

Answers (4)

Typo Johnson
Typo Johnson

Reputation: 6044

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

Upvotes: 0

caprosky
caprosky

Reputation: 41

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..

Upvotes: 2

Amagrammer
Amagrammer

Reputation: 6373

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

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

Upvotes: 1

Jordan
Jordan

Reputation: 21770

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.

Upvotes: 0

Related Questions