Here Im Getting memory leak at
eventTextField.keyboardAppearance = UIKeyboardAppearanceDefault;
I declared the textfield globally and I allocated the text field in CellForRowAtIndex and my code is:
if(indexPath.section == 1)
{
eventTextField = [[UITextField alloc]initWithFrame:CGRectMake(10, 15, 300, 50)];
eventTextField.placeholder = @"Event Name:";
[eventTextField setFont:[UIFont boldSystemFontOfSize:14]];
eventTextField.returnKeyType = UIReturnKeyNext;
eventTextField.keyboardAppearance = UIKeyboardAppearanceDefault;
eventTextField.keyboardType = UIKeyboardTypeDefault;
eventTextField.delegate=self;
if(isRightButton == YES)
{
eventTextField.enabled = NO;
}
else
{
eventTextField.enabled = YES;
}
if([event.eventName length] > 0)
{
eventTextField.text = event.eventName;
}
else
{
eventTextField.text = @"";
}
[elementView addSubview:eventTextField];
cell.accessoryType = UITableViewCellAccessoryNone;
}
and I release the textfield in dealloc.
when Im checking the object allocations it showing leak at:
eventTextField.keyboardAppearance = UIKeyboardAppearanceDefault;
guys please help me to get out of this.
Anyone’s help will be appreciated.
Thank you,
Monish Kumar.
Simply add:
after:
This works because addSubview will retain the subview and release it when the view itself is released, so you can safely release the textfield after adding it to the view.
Golden Rule: Anytime you call alloc or copy or retain, you should always call release (or autorelease).