Skip to content

Commit

Permalink
fix(addressbook): use pool to lower memory usage
Browse files Browse the repository at this point in the history
  • Loading branch information
cgx committed Oct 1, 2021
1 parent 4e6a7f5 commit a073241
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion SoObjects/Contacts/SOGoContactSourceFolder.m
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ - (void) _appendComponentProperties: (NSArray *) properties
else
[self appendMissingObjectRef: url
toBuffer: buffer];
if (count % 10 == 0)
if (count > 0 && count % 10 == 0)
{
RELEASE(pool);
pool = [[NSAutoreleasePool alloc] init];
Expand Down
18 changes: 16 additions & 2 deletions SoObjects/SOGo/LDAPSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -1288,11 +1288,13 @@ - (NSArray *) fetchContactsMatching: (NSString *) match
withCriteria: (NSArray *) criteria
inDomain: (NSString *) theDomain
{
NSAutoreleasePool *pool;
NGLdapConnection *ldapConnection;
NGLdapEntry *currentEntry;
NSEnumerator *entries;
NSMutableArray *contacts;
EOQualifier *qualifier;
unsigned int i;

contacts = [NSMutableArray array];

Expand All @@ -1313,9 +1315,21 @@ - (NSArray *) fetchContactsMatching: (NSString *) match
entries = [ldapConnection deepSearchAtBaseDN: _baseDN
qualifier: qualifier
attributes: _lookupFields];

i = 0;
pool = [NSAutoreleasePool new];
while ((currentEntry = [entries nextObject]))
[contacts addObject:
[self _convertLDAPEntryToContact: currentEntry]];
{
[contacts addObject:
[self _convertLDAPEntryToContact: currentEntry]];
i++;
if (i % 10 == 0)
{
[pool release];
pool = [NSAutoreleasePool new];
}
}
[pool release];
}

return contacts;
Expand Down
6 changes: 6 additions & 0 deletions SoObjects/SOGo/SOGoUserManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/

#import <Foundation/NSAutoreleasePool.h>

#import <NGExtensions/NSNull+misc.h>
#import <NGExtensions/NSObject+Logs.h>

Expand Down Expand Up @@ -1202,6 +1205,7 @@ - (NSArray *) _fetchEntriesInSources: (NSArray *) sourcesList
matching: (NSString *) filter
inDomain: (NSString *) domain
{
NSAutoreleasePool *pool;
NSMutableArray *contacts;
NSEnumerator *sources;
NSString *sourceID;
Expand All @@ -1211,11 +1215,13 @@ - (NSArray *) _fetchEntriesInSources: (NSArray *) sourcesList
sources = [sourcesList objectEnumerator];
while ((sourceID = [sources nextObject]))
{
pool = [[NSAutoreleasePool alloc] init];
currentSource = [_sources objectForKey: sourceID];
[contacts addObjectsFromArray:
[currentSource fetchContactsMatching: filter
withCriteria: nil
inDomain: domain]];
RELEASE(pool);
}

return [self _compactAndCompleteContacts: [contacts objectEnumerator]];
Expand Down

0 comments on commit a073241

Please sign in to comment.