我正在分析我的应用程序并面对存储到设置用户名和设置密码值的对象的潜在泄漏我的代码被给出
-(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;
}
}
答案 0 :(得分:0)
CFPreferencesCopyAppValue返回的字符串遵循Core Foundation中的Create规则(https://developer.apple.com/library/ios/documentation/CoreFoundation/Conceptual/CFMemoryMgmt/Concepts/Ownership.html#//apple_ref/doc/uid/20001148-103029) - 完成后需要调用CFRelease。 ARC 不为您执行此操作。
答案 1 :(得分:0)
使用CFBridgingRelease
将对象的所有权转移到ARC,而不是简单的C风格转换:
NSString *tempString = (NSString*)CFBridgingRelease(settingPasswordValue);