Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jync opened this issue Jul 24, 2017 · 1 comment
Open

Comments

@jync
Copy link

jync commented Jul 24, 2017

  • 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?

@belkevich
Copy link
Contributor

Hi @jync,

Thank you for issue and sorry for delay.
Unfortunately there is no another way to handle contacts except loadContacts method.
But if you know proper solution or something that can help avoid memory warnings (like placing objects in autorelease pool) I'll add it to source code and release it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants