Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9097367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:05:36+00:00 2026-06-17T00:05:36+00:00

I have a strange thing happening with ABAddressBook. Here is some code: – (NSArray*)addressBookArray

  • 0

I have a strange thing happening with ABAddressBook. Here is some code:

- (NSArray*)addressBookArray {

    ABAddressBookRef addressBook = NULL;
    NSArray *temp = nil;

    if(&ABAddressBookCreateWithOptions != NULL) {

        CFErrorRef error = nil;
        addressBook = ABAddressBookCreateWithOptions(NULL, &error);
        ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {

            dispatch_async(dispatch_get_main_queue(), ^{
                if(error) {
                    // handle error
                }
                else if(!granted) {
                    // handle not granted
                }
            });
        });
    }
    else { // iOS 5
        addressBook = ABAddressBookCreate();
    }
    if(addressBook) {
        temp = (__bridge_transfer NSArray*)ABAddressBookCopyArrayOfAllPeople(addressBook);
        CFRelease(addressBook);
    }
    return temp;
}

- (NSArray*)emailList {

    NSArray *temp = [self addressBookArray];
    NSMutableArray *list = nil;

    if(temp) {

        int n = temp.count;
        list = [NSMutableArray arrayWithCapacity:n];

        for(int i = 0; i < n ; i++) {

            ABRecordRef person = (__bridge ABRecordRef)[temp objectAtIndex:i];
            NSString *name = (__bridge_transfer NSString*)ABRecordCopyCompositeName(person);

            if(name) {
                ABMultiValueRef emails = ABRecordCopyValue(person, kABPersonEmailProperty);

                if(emails) {
                    int cnt = ABMultiValueGetCount(emails);

                    for(int j = 0; j < cnt; j++) {
                        NSString *email = (__bridge_transfer NSString*)ABMultiValueCopyValueAtIndex(emails, j);

                        if(email) {
                            [list addObject:email];
                            break;
                        }
                    }
                    CFRelease(emails);
                }
            }
        }
    }
    return list;
}

If I call emailList and comment out CFRelease(addressBook), I get a warning of a possible leak in XCode’s Analyze, but my code behaves properly.

If I uncomment CFRelease(addressBook), there is no leak warning, ABRecordRef person and NSString *name have proper values, BUT ABMultiValueRef emails if always nil.

Confused.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T00:05:38+00:00Added an answer on June 17, 2026 at 12:05 am

    While it surprises me somewhat, I suspect that the ABPerson is not completely defined without its ABAddressBook. So the address book needs to exist for as long as the person. Given that, as long as this is all single-threaded, you may want to store your ABAddressBook in an ivar so you don’t have to create and destroy it all the time. If it’s multi-threaded, remember that you need a separate ABAddressBook per thread.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

CSS newbie here. Strange thing is happening, I have gaps between links, and I
I have this strange thing happening to my code. Using Firefox or Chrome (tried
Hi guys I have a very frustrating and strange thing happening here, when I
I have an FBML app and a strange thing keeps happening. If I go
I have a strange thing happening with php files. As an example: domain.com/test.php domain.com/test
I have a strange thing happening while using ZedGraph . I am using the
I have a strange thing happening with my app now after iOS5 updates. I
I have a strange thing happening in my js script. When the click function
I have noticed a strange thing happening in jQuery and wonder if anyone knows
I've got some strange behaviour happening I can't work out. I've written some code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.