0

我正在分析我的应用程序并面临存储到设置用户名和设置密码值的对象的潜在泄漏给我的代码

-(void) checkRememberPassword{
        CFStringRef userNameKey = CFSTR("user_id_preferences");
        CFStringRef settingUserName = (CFStringRef)CFPreferencesCopyAppValue(userNameKey, kCFPreferencesCurrentApplication);
        CFStringRef passwordKey = CFSTR("password_preferences");
        CFStringRef settingPasswordValue = (CFStringRef)CFPreferencesCopyAppValue(passwordKey, kCFPreferencesCurrentApplication);
        NSString *tempString = (__bridge NSString *)settingPasswordValue;
        NSString *tempString1 = (__bridge NSString *)settingUserName;
        if(([tempString1 length] != 0) || ([tempString length] !=0)){
            txtUserName.text = (__bridge NSString *)settingUserName;
            txtPassword.text = (__bridge NSString *)settingPasswordValue;
            [checkBoxButton setImage:[UIImage imageNamed:@"checkbox_full.png"] forState:UIControlStateNormal];
            flagForRemPassword = YES;

        }
    }
4

2 回答 2

0

CFPreferencesCopyAppValue 返回的字符串遵循创建规则 ( https://developer.apple.com/library/ios/documentation/CoreFoundation/Conceptual/CFMemoryMgmt/Concepts/Ownership.html#//apple_ref/doc/uid/20001148-103029 )在 Core Foundation 中——完成后需要调用 CFRelease。ARC 不会您执行此操作。

于 2013-11-11T22:08:40.737 回答
0

用于CFBridgingRelease将对象的所有权转移到 ARC,而不是简单的 C 样式转换:

NSString *tempString = (NSString*)CFBridgingRelease(settingPasswordValue);
于 2013-11-11T22:26:31.847 回答