From a073241e0f4ff9c761a7f6b25502a6000bb1bf89 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Fri, 1 Oct 2021 11:11:00 -0400 Subject: [PATCH] fix(addressbook): use pool to lower memory usage --- SoObjects/Contacts/SOGoContactSourceFolder.m | 2 +- SoObjects/SOGo/LDAPSource.m | 18 ++++++++++++++++-- SoObjects/SOGo/SOGoUserManager.m | 6 ++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/SoObjects/Contacts/SOGoContactSourceFolder.m b/SoObjects/Contacts/SOGoContactSourceFolder.m index 62cb4a123..7f4c9676d 100644 --- a/SoObjects/Contacts/SOGoContactSourceFolder.m +++ b/SoObjects/Contacts/SOGoContactSourceFolder.m @@ -691,7 +691,7 @@ else [self appendMissingObjectRef: url toBuffer: buffer]; - if (count % 10 == 0) + if (count > 0 && count % 10 == 0) { RELEASE(pool); pool = [[NSAutoreleasePool alloc] init]; diff --git a/SoObjects/SOGo/LDAPSource.m b/SoObjects/SOGo/LDAPSource.m index a5cbfb1d2..24c31e35b 100644 --- a/SoObjects/SOGo/LDAPSource.m +++ b/SoObjects/SOGo/LDAPSource.m @@ -1288,11 +1288,13 @@ groupObjectClasses: (NSArray *) newGroupObjectClasses withCriteria: (NSArray *) criteria inDomain: (NSString *) theDomain { + NSAutoreleasePool *pool; NGLdapConnection *ldapConnection; NGLdapEntry *currentEntry; NSEnumerator *entries; NSMutableArray *contacts; EOQualifier *qualifier; + unsigned int i; contacts = [NSMutableArray array]; @@ -1313,9 +1315,21 @@ groupObjectClasses: (NSArray *) newGroupObjectClasses 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; diff --git a/SoObjects/SOGo/SOGoUserManager.m b/SoObjects/SOGo/SOGoUserManager.m index 74820df94..832cdf38c 100644 --- a/SoObjects/SOGo/SOGoUserManager.m +++ b/SoObjects/SOGo/SOGoUserManager.m @@ -17,6 +17,9 @@ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ + +#import + #import #import @@ -1202,6 +1205,7 @@ static Class NSNullK; matching: (NSString *) filter inDomain: (NSString *) domain { + NSAutoreleasePool *pool; NSMutableArray *contacts; NSEnumerator *sources; NSString *sourceID; @@ -1211,11 +1215,13 @@ static Class NSNullK; 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]];