Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 7e75814

Browse files
authored
Optimize memory management for manifest hashing in IOS (#584)
Prevents app memory from skyrocketing during sync if the local package contains many large files.
1 parent 7bf9f62 commit 7e75814

1 file changed

Lines changed: 20 additions & 18 deletions

File tree

src/ios/UpdateHashUtils.m

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,27 @@ + (void)addFolderEntriesToManifest:(NSString*)folderPath
2929
}
3030

3131
for (NSString* fileName in folderFiles) {
32-
if ([[self ignoredFilenames] containsObject:fileName]) {
33-
continue;
34-
}
35-
NSString* fullFilePath = [folderPath stringByAppendingPathComponent:fileName];
36-
NSString* relativePath = [pathPrefix stringByAppendingPathComponent:fileName];
37-
BOOL isDir = NO;
38-
if ([[NSFileManager defaultManager] fileExistsAtPath:fullFilePath
39-
isDirectory:&isDir] && isDir) {
40-
[self addFolderEntriesToManifest:fullFilePath
41-
pathPrefix:relativePath
42-
manifestEntries:manifestEntries
43-
error:error];
44-
if (*error) {
45-
return;
32+
@autoreleasepool {
33+
if ([[self ignoredFilenames] containsObject:fileName]) {
34+
continue;
35+
}
36+
NSString* fullFilePath = [folderPath stringByAppendingPathComponent:fileName];
37+
NSString* relativePath = [pathPrefix stringByAppendingPathComponent:fileName];
38+
BOOL isDir = NO;
39+
if ([[NSFileManager defaultManager] fileExistsAtPath:fullFilePath
40+
isDirectory:&isDir] && isDir) {
41+
[self addFolderEntriesToManifest:fullFilePath
42+
pathPrefix:relativePath
43+
manifestEntries:manifestEntries
44+
error:error];
45+
if (*error) {
46+
return;
47+
}
48+
} else {
49+
NSData* fileContents = [NSData dataWithContentsOfFile:fullFilePath];
50+
NSString* fileContentsHash = [self computeHashForData:fileContents];
51+
[manifestEntries addObject:[[relativePath stringByAppendingString:@":"] stringByAppendingString:fileContentsHash]];
4652
}
47-
} else {
48-
NSData* fileContents = [NSData dataWithContentsOfFile:fullFilePath];
49-
NSString* fileContentsHash = [self computeHashForData:fileContents];
50-
[manifestEntries addObject:[[relativePath stringByAppendingString:@":"] stringByAppendingString:fileContentsHash]];
5153
}
5254
}
5355
}

0 commit comments

Comments
 (0)