2

I am building an app that requires me to pick first name and last name from contact. On running with Build Analyser I got memory leak in this chunk of codes.

ABMutableMultiValueRef fName = ABRecordCopyValue(person, kABPersonFirstNameProperty);
ABMutableMultiValueRef lName = ABRecordCopyValue(person, kABPersonLastNameProperty);    
if(fName){
    self.firstNameText.text = fName;
}
if (lName) {
    self.lastNameText.text = lName;
}
CFRelease(fName);
CFRelease(lName);

I am really tired of fixing it but was unable to. Kindly help me out.

Any kind of help would be highly appriciated.

Thanks in advance!!

iCoder4777
  • 1,682
  • 1
  • 14
  • 35
  • 2
    The data type for `fName` and `lName` are incorrect. They should be `CFStringRef`. Which line of code exactly is the analyzer commenting on? What about releasing `person`? – rmaddy Nov 08 '12 at 05:20

1 Answers1

-3

Hello this are the delegate methods.

in - (BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person method you can retrive any user infromation like kABPersonFirstNameProperty for first name,kABPersonLastNameProperty for last name property

  - (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker {
// assigning control back to the main controller
[self dismissModalViewControllerAnimated:YES];
}

  - (BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person {
NSString *firstname=(NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
Usernametf.text=firstname;
//  NSMutableDictionary *dict=[[NSMutableDictionary alloc] initWithObjectsAndKeys:firstname,@"FirstName", nil];
//[selectedemailArray addObject:dict];
   // NSLog(@"\n array is %@",selectedemailArray);


//[objDatabase insertArray:selectedemailArray forTable:@"EmailList"];
//[objDatabase insertDictionary:dict forTable:@"EmailList"];
//    [dict release];
//    dict =nil;

// remove the controller
[self dismissModalViewControllerAnimated:YES];
return NO;

}

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier{
return NO;
}

let me know is it working or not..!!!!

Happy coding!!!!!

NiravPatel
  • 3,260
  • 2
  • 21
  • 31