From 14630ce222b4c4c43cf5ed04999dd02f5bf5edaf Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Tue, 27 Nov 2012 15:53:39 -0500 Subject: [PATCH] Improve memory usage of "sogo-tool restore" Used an autorelease pool. --- Tools/SOGoToolRestore.m | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Tools/SOGoToolRestore.m b/Tools/SOGoToolRestore.m index 3b19fff7c..0cdda3b29 100644 --- a/Tools/SOGoToolRestore.m +++ b/Tools/SOGoToolRestore.m @@ -21,6 +21,7 @@ */ #import +#import #import #import #import @@ -346,6 +347,7 @@ typedef enum SOGoToolRestoreMode { - (BOOL) restoreRecords: (NSArray *) records ofFolder: (GCSFolder *) gcsFolder { + NSAutoreleasePool *pool; NSDictionary *existingRecords, *currentRecord; NSString *cName, *cContent; int count, max; @@ -354,12 +356,18 @@ typedef enum SOGoToolRestoreMode { if (records) { + existingRecords = [self fetchExistingRecordsFromFolder: gcsFolder]; + pool = [[NSAutoreleasePool alloc] init]; version = 0; rc = YES; - existingRecords = [self fetchExistingRecordsFromFolder: gcsFolder]; max = [records count]; for (count = 0; count < max; count++) { + if (count > 0 && count%100 == 0) + { + DESTROY(pool); + pool = [[NSAutoreleasePool alloc] init]; + } currentRecord = [records objectAtIndex: count]; cName = [currentRecord objectForKey: @"c_name"]; if (![existingRecords objectForKey: cName]) @@ -370,6 +378,7 @@ typedef enum SOGoToolRestoreMode { baseVersion: &version]; } } + DESTROY(pool); } else {