Local pool when appending contacts to response

Avoids using too much memory when doing a contact lookup with many matches
This commit is contained in:
Jean Raby committed 2013-09-13 11:16:28 -04:00
1 parent 0c38a9e555
commit de8bf64c70
1 file changed
+23 -10
+23 -10
View File
@@ -21,6 +21,7 @@
*/ */
#import <Foundation/NSArray.h> #import <Foundation/NSArray.h>
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSDictionary.h> #import <Foundation/NSDictionary.h>
#import <Foundation/NSEnumerator.h> #import <Foundation/NSEnumerator.h>
@@ -91,7 +92,8 @@
toResponse: (WOResponse *) response toResponse: (WOResponse *) response
context: (id) localContext context: (id) localContext
{ {
unsigned int count, max; unsigned int count,i , max;
NSAutoreleasePool *pool;
NSDictionary *currentFilter, *contact; NSDictionary *currentFilter, *contact;
NSEnumerator *contacts; NSEnumerator *contacts;
NSString *baseURL, *domain; NSString *baseURL, *domain;
@@ -103,16 +105,27 @@
for (count = 0; count < max; count++) for (count = 0; count < max; count++)
{ {
currentFilter = [filters objectAtIndex: count]; currentFilter = [filters objectAtIndex: count];
contacts = [[(id<SOGoContactFolder>)self lookupContactsWithFilter: [[currentFilter allValues] lastObject] contacts =
onCriteria: @"name_or_address" [[(id<SOGoContactFolder>)self lookupContactsWithFilter: [[currentFilter allValues] lastObject]
sortBy: @"c_givenname" onCriteria: @"name_or_address"
ordering: NSOrderedDescending sortBy: @"c_givenname"
inDomain: domain] ordering: NSOrderedDescending
objectEnumerator]; inDomain: domain] objectEnumerator];
pool = [[NSAutoreleasePool alloc] init];
i = 0;
while ((contact = [contacts nextObject])) 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);
} }
} }