Improve memory usage of "sogo-tool restore"

Used an autorelease pool.
pull/7/head
Francis Lachapelle 2012-11-27 15:53:39 -05:00
parent e523926ef5
commit 14630ce222
1 changed files with 10 additions and 1 deletions

View File

@ -21,6 +21,7 @@
*/ */
#import <Foundation/NSArray.h> #import <Foundation/NSArray.h>
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSError.h> #import <Foundation/NSError.h>
#import <Foundation/NSFileManager.h> #import <Foundation/NSFileManager.h>
#import <Foundation/NSString.h> #import <Foundation/NSString.h>
@ -346,6 +347,7 @@ typedef enum SOGoToolRestoreMode {
- (BOOL) restoreRecords: (NSArray *) records - (BOOL) restoreRecords: (NSArray *) records
ofFolder: (GCSFolder *) gcsFolder ofFolder: (GCSFolder *) gcsFolder
{ {
NSAutoreleasePool *pool;
NSDictionary *existingRecords, *currentRecord; NSDictionary *existingRecords, *currentRecord;
NSString *cName, *cContent; NSString *cName, *cContent;
int count, max; int count, max;
@ -354,12 +356,18 @@ typedef enum SOGoToolRestoreMode {
if (records) if (records)
{ {
existingRecords = [self fetchExistingRecordsFromFolder: gcsFolder];
pool = [[NSAutoreleasePool alloc] init];
version = 0; version = 0;
rc = YES; rc = YES;
existingRecords = [self fetchExistingRecordsFromFolder: gcsFolder];
max = [records count]; max = [records count];
for (count = 0; count < max; count++) for (count = 0; count < max; count++)
{ {
if (count > 0 && count%100 == 0)
{
DESTROY(pool);
pool = [[NSAutoreleasePool alloc] init];
}
currentRecord = [records objectAtIndex: count]; currentRecord = [records objectAtIndex: count];
cName = [currentRecord objectForKey: @"c_name"]; cName = [currentRecord objectForKey: @"c_name"];
if (![existingRecords objectForKey: cName]) if (![existingRecords objectForKey: cName])
@ -370,6 +378,7 @@ typedef enum SOGoToolRestoreMode {
baseVersion: &version]; baseVersion: &version];
} }
} }
DESTROY(pool);
} }
else else
{ {