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 6699311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:40:49+00:00 2026-05-26T06:40:49+00:00

//get instance of shared addressbook ABAddressBookRef addressBook = ABAddressBookCreate(); //get all contacts in addressbook

  • 0

//get instance of shared addressbook
ABAddressBookRef addressBook = ABAddressBookCreate();

//get all contacts in addressbook
CFArrayRef allContacts = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFIndex numPeople = ABAddressBookGetPersonCount(addressBook);


self.contacts = [NSMutableArray array];

//modify data to be stored in an array
for (int i = 0; i < numPeople; i++) {

    AddressBookPerson *person = [[AddressBookPerson alloc] init];

    ABRecordRef ref = CFArrayGetValueAtIndex(allContacts, i);

    NSString *firstName = (NSString *)ABRecordCopyValue(ref, kABPersonFirstNameProperty);
    NSString *lastName = (NSString *)ABRecordCopyValue(ref, kABPersonLastNameProperty);

    ABMultiValueRef phoneNumberProperty = ABRecordCopyValue(ref, kABPersonPhoneProperty);
    NSArray* phoneNumbers = (NSArray*)ABMultiValueCopyArrayOfAllValues(phoneNumberProperty);
    CFRelease(phoneNumberProperty);


    NSString *contactFirstLast = [NSString stringWithFormat: @"%@, %@", firstName, lastName];

    person.name = contactFirstLast;
    person.phoneNumbers = phoneNumbers;

    [self.contacts addObject:person];
    //self.contacts = [NSArray arrayWithArray:listOfContacts];
    [contactFirstLast release];
    [person release];

}

I’m not sure why this property is not retaining. I have even attempted tried variations such as:

self.contacts = [[NSMutableArray alloc] init];

it is allocated but any object I place inside doesn’t get retained. I used a different array altogether which is not a property and the objects were retained just fine. But the problem is I need to have a global property to contain the values.

UPDATE:

I found the solution to the problem. I ran analyze and did ref counting as well, I got it to the point where there are no memory leaks. But the issue remained and it was because of the name of the property.

“contacts” is a built in property for “The set of MIDI network hosts available for initiating connections and for managing incoming connection requests.”

I named my property a unique name and all the problems disappeared. There is no need for a static variable and I understand that, I was using that variable for testing to see what was going on with my objects. The reason the static variable worked was because it was uniquely named.

  • 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-05-26T06:40:50+00:00Added an answer on May 26, 2026 at 6:40 am

    The short answer: NSMutableArray is retaining the objects, your program’s implementation has errors in its reference counting.

    Please remove all compiler warnings and then run the static analyzer and fix those issues.

    (the static analyzer should point out the reference count errors in your program)

    Update

    The static analysis shows:

    contactFirstLast << over-release
    allContacts << leaked
    firstName << leaked
    lastName << leaked
    phoneNumbers << leaked
    

    This comes to one reference count issue per 4 lines of code, and there are tools dying to help you =)

    You really can’t write a nontrivial program until you can do ref counting correctly. You should know it so well, that it is automatic.

    Those 5 issues I pointed out may not solve the first issue that you encounter during execution, but fixing each and every one of these issues in your program will remove many active bugs in your program (they are waiting to be discovered).

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

Sidebar

Related Questions

What I am trying to do is to get instance of Doctrine EM (using
I need to get an instance of the application's MembershipProvider from within a controller.
I would like to get View instance that is used to display specific Preference
I'm looking to get an instance of Solr search running on my localhost. The
I'm trying to get the instance name of my class. The way I do
I have written the following Utility class to get an instance of any class
I am a little confused about how I set and get the instance variables
I've created a singleton class which uses GetInstance() method to get the instance address
Reading this When a bean is a singleton, only one shared instance of the
so i need a NSDocument with a backend instance that all views can access

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.