开发者

potential leak at CFStringRef while getting phone number from contacts

开发者 https://www.devze.com 2023-02-06 00:07 出处:网络
I am getting phone number from the address book for that i am using this code. - (IBAction)contacts { ABPeoplePickerNavigationController *peoplePickerController = [[ABPeoplePickerNavigationCont开发

I am getting phone number from the address book for that i am using this code.

- (IBAction)contacts {


    ABPeoplePickerNavigationController *peoplePickerController = [[ABPeoplePickerNavigationCont开发者_StackOverflow中文版roller alloc] init];
    peoplePickerController.peoplePickerDelegate = self;
    [self presentModalViewController:peoplePickerController animated:NO];
    [peoplePickerController release];

}
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
      shouldContinueAfterSelectingPerson:(ABRecordRef)person {


    return YES;
}

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
  shouldContinueAfterSelectingPerson:(ABRecordRef)person
                            property:(ABPropertyID)property
                          identifier:(ABMultiValueIdentifier)identifier {
if (property == kABPersonPhoneProperty) {
    ABMultiValueRef phonenumbers = ABRecordCopyValue(person, property);
    CFStringRef phonenumberselected = ABMultiValueCopyValueAtIndex(phonenumbers, identifier);

    NSString *aNSString = (NSString *)phonenumberselected;
    if ([share_toadd length] == 0) {
        [share_toadd appendString:aNSString];
    }
    else {
        [share_toadd appendString:@","];
        [share_toadd appendString:aNSString];
    }

    share_textfield.text = share_toadd;
    // Return to the main view controller.
    [ self dismissModalViewControllerAnimated:YES ];
    return NO;

    [share_textfield release];
}   
return YES;

}

but i am getting potential leak at CFStringRef

 Potential leak of an object allocated on line 1126

 Call to function 'ABRecordCopyValue' returns a Core Foundation object with a +1 retain count (owning reference)

 Object allocated on line 1126 is no longer referenced after this point and has a retain count of +1 (object leaked)

can any one pls help me.

how can i resolve it.


You should call CFRelease(phonenumbersselected) when you're done using the object.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号