Skip to content

APAddressBook excessive memory consumption with a large number of contacts #163

@jync

Description

@jync
  • APAddressBook/Core (0.3.1)
  • APAddressBook/Swift (0.3.1)

We're using APAddressBook to load native contacts to search against. However, for some of our users who have > 10k native contacts, the app seems to be consuming too much memory, causing an unexpected JetSam event and terminating the app.

Looking at the method where contacts are being extracted:

- (NSArray *)allContactsWithContactFieldMask:(APContactField)fieldMask
{
    NSMutableArray *contacts = [[NSMutableArray alloc] init];
    if (!self.wrapper.error)
    {
        CFArrayRef peopleArrayRef = ABAddressBookCopyArrayOfAllPeople(self.wrapper.ref);
        CFIndex count = CFArrayGetCount(peopleArrayRef);
        for (CFIndex i = 0; i < count; i++)
        {
            ABRecordRef recordRef = CFArrayGetValueAtIndex(peopleArrayRef, i);
            APContact *contact = [self.builder contactWithRecordRef:recordRef fieldMask:fieldMask];
            [contacts addObject:contact];
        }
        CFRelease(peopleArrayRef);
    }
    return contacts.count > 0 ? contacts.copy : nil;
}

Would it be better if we call this method using an autorelease pool and batching up contacts? Is there a better way to handle the large volume of contacts with APAddressBook?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions