added autorelease pools to reduce memory consumption

This commit is contained in:
Stefan Reitshamer 2011-08-16 15:45:59 -04:00
parent 1a5a2ae998
commit e85530cfb0

View file

@ -45,6 +45,7 @@
+ (NSString *)errorDomain; + (NSString *)errorDomain;
- (BOOL)verifyTree:(BlobKey *)theTreeBlobKey path:(NSString *)path error:(NSError **)error; - (BOOL)verifyTree:(BlobKey *)theTreeBlobKey path:(NSString *)path error:(NSError **)error;
- (BOOL)verifyTree:(BlobKey *)theTreeBlobKey path:(NSString *)path childNodeName:(NSString *)childNodeName node:(Node *)node error:(NSError **)error;
- (BOOL)verify:(BlobKey *)theBlobKey error:(NSError **)error; - (BOOL)verify:(BlobKey *)theBlobKey error:(NSError **)error;
@end @end
@ -93,20 +94,39 @@
} else { } else {
printf("head commit for s3Bucket %s computerUUID %s bucketUUID %s is %s\n", [s3BucketName UTF8String], [computerUUID UTF8String], [bucketUUID UTF8String], [[headBlobKey description] UTF8String]); printf("head commit for s3Bucket %s computerUUID %s bucketUUID %s is %s\n", [s3BucketName UTF8String], [computerUUID UTF8String], [bucketUUID UTF8String], [[headBlobKey description] UTF8String]);
BlobKey *commitBlobKey = headBlobKey; BlobKey *commitBlobKey = headBlobKey;
BOOL ret = YES;
NSAutoreleasePool *pool = nil;
while (commitBlobKey != nil) { while (commitBlobKey != nil) {
[commitBlobKey retain];
[pool drain];
pool = [[NSAutoreleasePool alloc] init];
[commitBlobKey autorelease];
printf("verifying commit %s bucketUUID %s\n", [[commitBlobKey description] UTF8String], [bucketUUID UTF8String]); printf("verifying commit %s bucketUUID %s\n", [[commitBlobKey description] UTF8String], [bucketUUID UTF8String]);
Commit *commit = [repo commitForBlobKey:commitBlobKey error:error]; Commit *commit = [repo commitForBlobKey:commitBlobKey error:error];
if (commit == nil) { if (commit == nil) {
return NO; ret = NO;
break;
} }
if (verbose) { if (verbose) {
printf("commit %s's tree is %s\n", [[commitBlobKey description] UTF8String], [[[commit treeBlobKey] description] UTF8String]); printf("commit %s's tree is %s\n", [[commitBlobKey description] UTF8String], [[[commit treeBlobKey] description] UTF8String]);
} }
if (![self verifyTree:[commit treeBlobKey] path:@"/" error:error]) { if (![self verifyTree:[commit treeBlobKey] path:@"/" error:error]) {
return NO; ret = NO;
break;
} }
commitBlobKey = [[commit parentCommitBlobKeys] anyObject]; commitBlobKey = [[commit parentCommitBlobKeys] anyObject];
} }
if (!ret && error != NULL) {
[*error retain];
}
[pool drain];
if (!ret && error != NULL) {
[*error autorelease];
}
if (!ret) {
return NO;
}
} }
printf("%qu packed blobs; %qu non-packed blobs\n", packedBlobCount, nonPackedBlobCount); printf("%qu packed blobs; %qu non-packed blobs\n", packedBlobCount, nonPackedBlobCount);
return YES; return YES;
@ -145,8 +165,31 @@
return NO; return NO;
} }
} }
for (NSString *childNodeName in [tree childNodeNames]) { BOOL ret = YES;
NSArray *childNodeNames = [tree childNodeNames];
NSAutoreleasePool *pool = nil;
for (NSString *childNodeName in childNodeNames) {
[childNodeName retain];
[pool release];
pool = [[NSAutoreleasePool alloc] init];
[childNodeName autorelease];
Node *node = [tree childNodeWithName:childNodeName]; Node *node = [tree childNodeWithName:childNodeName];
if (![self verifyTree:theTreeBlobKey path:path childNodeName:childNodeName node:node error:error]) {
ret = NO;
break;
}
}
if (!ret && error != NULL) {
[*error retain];
}
[pool drain];
if (!ret && error != NULL) {
[*error autorelease];
}
return ret;
}
- (BOOL)verifyTree:(BlobKey *)theTreeBlobKey path:(NSString *)path childNodeName:(NSString *)childNodeName node:(Node *)node error:(NSError **)error {
NSArray *dataBlobKeys = [node dataBlobKeys]; NSArray *dataBlobKeys = [node dataBlobKeys];
NSString *childPath = [path stringByAppendingPathComponent:childNodeName]; NSString *childPath = [path stringByAppendingPathComponent:childNodeName];
if ([node isTree]) { if ([node isTree]) {
@ -201,7 +244,6 @@
} }
} }
} }
}
return YES; return YES;
} }
- (BOOL)verify:(BlobKey *)theBlobKey error:(NSError **)error { - (BOOL)verify:(BlobKey *)theBlobKey error:(NSError **)error {