Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

memory leaks at showing UIKeyboard on ARC

Tags:

ios

iphone

When UIKeyboard is called, memory is allocated and not freed when UIKeyboard is hidden. If it is the framework who is caching it, is there any way to clear it up? These code is what I use to create the UITextField and how I hide the UIKeyboard:

    #import <UIKit/UIKit.h>

    @interface SignInTextField : UITextField

    -(id)initWithIndexPath:(NSIndexPath*)indexPath;

    @end

    #import "SignInTextField.h"

    @implementation SignInTextField

    -(id)initWithIndexPath:(NSIndexPath*)indexPath{
        self = [super init];
        if (self) {
            if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
                // iPad
                self.frame = CGRectMake(110, 10, 600, 30);
            } else {
                self.frame = CGRectMake(110, 11, 150, 30);
            }

            self.tag = [indexPath row];
            self.returnKeyType = UIReturnKeyDone;
            self.autocapitalizationType = UITextAutocapitalizationTypeNone;
        }
        return self;
    }

    //SettingTextField
    SignInTextField *textField = [[SignInTextField alloc]initWithIndexPath:indexPath];
    textField.delegate = self;

    #pragma mark - Text Field CallBack
    -(void)textFieldDidBeginEditing:(UITextField *)textField{
        activeField = textField;
    }

    - (void)textFieldDidEndEditing:(UITextField *)textField {

        if(textField.tag == 0) temp_email = [NSString         stringWithFormat:@"%@",textField.text];
        if(textField.tag == 1) temp_password = [NSString stringWithFormat:@"%@",textField.text];
    }

    - (BOOL)textFieldShouldReturn:(UITextField *)textField {
        [textField resignFirstResponder];
        return YES;
   }

This is leak point.

like image 275
JohnyDgoode Avatar asked Feb 18 '23 03:02

JohnyDgoode


1 Answers

When you open the Keyboard for first time, it is cached by iOS native framework. Its handle by UIKit framework.

Its not the memory leak. Next time onwards when there will be a requirement to display keyboard, application will use cached keyboard.

If the memory requirement goes high, native framework will release the cached views, if required. Still the application needs memory, framework will generate memory warnings for same.

like image 82
Apurv Avatar answered Feb 23 '23 23:02

Apurv