From de8bf64c70ca5f0b3cc9741d2bb933c0aef1e833 Mon Sep 17 00:00:00 2001 From: Jean Raby Date: Fri, 13 Sep 2013 11:16:28 -0400 Subject: [PATCH] Local pool when appending contacts to response Avoids using too much memory when doing a contact lookup with many matches --- SoObjects/Contacts/SOGoFolder+CardDAV.m | 33 +++++++++++++++++-------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/SoObjects/Contacts/SOGoFolder+CardDAV.m b/SoObjects/Contacts/SOGoFolder+CardDAV.m index ab6bee2da..2644e228f 100644 --- a/SoObjects/Contacts/SOGoFolder+CardDAV.m +++ b/SoObjects/Contacts/SOGoFolder+CardDAV.m @@ -21,6 +21,7 @@ */ #import +#import #import #import @@ -91,7 +92,8 @@ toResponse: (WOResponse *) response context: (id) localContext { - unsigned int count, max; + unsigned int count,i , max; + NSAutoreleasePool *pool; NSDictionary *currentFilter, *contact; NSEnumerator *contacts; NSString *baseURL, *domain; @@ -103,16 +105,27 @@ for (count = 0; count < max; count++) { currentFilter = [filters objectAtIndex: count]; - contacts = [[(id)self lookupContactsWithFilter: [[currentFilter allValues] lastObject] - onCriteria: @"name_or_address" - sortBy: @"c_givenname" - ordering: NSOrderedDescending - inDomain: domain] - objectEnumerator]; - + contacts = + [[(id)self lookupContactsWithFilter: [[currentFilter allValues] lastObject] + onCriteria: @"name_or_address" + sortBy: @"c_givenname" + ordering: NSOrderedDescending + inDomain: domain] objectEnumerator]; + + pool = [[NSAutoreleasePool alloc] init]; + i = 0; while ((contact = [contacts nextObject])) - [self _appendObject: contact withBaseURL: baseURL - toREPORTResponse: response]; + { + [self _appendObject: contact withBaseURL: baseURL + toREPORTResponse: response]; + if (i % 10 == 0) + { + RELEASE(pool); + pool = [[NSAutoreleasePool alloc] init]; + } + i++; + } + RELEASE(pool); } }